I am having a problem in doing assignment at Coursera
Afficher commentaires plus anciens
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
Réponses (1)
Alan Stevens
le 14 Juil 2020
0 votes
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 commentaire
Keshu Ranjan
le 14 Juil 2020
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!