필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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 ...

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 4월 24일
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.

추가 답변 (1개)

HARSHA VARDHAN
HARSHA VARDHAN 2020년 12월 10일
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

카테고리

Help CenterFile Exchange에서 Platform and License에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by