I am having a problem in doing assignment at Coursera

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

Answers (1)

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'

Categories

Asked:

on 14 Jul 2020

Commented:

on 14 Jul 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!