Borrar filtros
Borrar filtros

I am having a problem in solving a coursera assignment can you please help me

2 visualizaciones (últimos 30 días)
The problem is as such: variable input function
Function called should take two arguments age and year,The function must return true if age is less than the limit. If limit is not mentioned it must have default as 21.Output argument name is too_young.
I have wrote a code can you please verify it,
function too_young=under_age(age,limit)
if nargin<2
limit=18;
end
if limit<18
too_young=true;
else
too_young=false;
end
Function call is as such:
too_young = under_age(18,18)
too_young = under_age(20)
I got the errors as such:
correct for 18 vs 18
Assessment result: incorrect20
Variable too_young has an incorrect value.
Assessment result: correct22
Assessment result: incorrect17 vs 18
Variable too_young has an incorrect value.
Assessment result: incorrect13 vs 12
Variable too_young has an incorrect value.
Assessment result: incorrectRandom tests
Variable too_young has an incorrect value.
under_age(21, 23) failed ...

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 24 de Abr. de 2020
Nikhil - Iook closely at this code
if limit<18
too_young=true;
else
too_young=false;
end
Why isn't age being used? What happens if the user has passed in a valid limit and now you are ignoring it by using 18? Try using the MATLAB debugger to step through the code and understand why the condition for your if statement is incorrect.

Más respuestas (1)

HARSHA VARDHAN
HARSHA VARDHAN el 10 de Dic. de 2020
function too_young=under_age(age,limit)
if nargin<2
limit=21;
end
if age<limit
too_young=true;
elseif age>=limit
too_young=false;
end

Categorías

Más información sobre Platform and License en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by