I am having a problem in doing assignment at Coursera
Mostrar comentarios más antiguos
Here the question is:
Write a function called under_age that takes two positive integer scalar arguments
1. age that represents someone's age
2. limit that represents age limit
The function returns true if person is younger that age limit. If the second argument limit is not provided it defaults to 21. The name of the output argument is too_young.
Here my answer:
function too_young=under_age(age,limit)
if nargin<2
limit=18;
end
if age<limit
too_young=true;
else
too_young=false;
end
And my output gives:
20: Variable too_young has an incorrect value
Respuestas (1)
Alan Stevens
el 14 de Jul. de 2020
0 votos
Your code has the limit 18 rather than 21. Given that, it produces the correct result.
If you want the words true or false returned enclose them within ''. e.g. 'true'
1 comentario
Keshu Ranjan
el 14 de Jul. de 2020
Categorías
Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!