If-statement assignment problem

조회 수: 1 (최근 30일)
Amit Tal
Amit Tal 2015년 8월 12일
답변: Walter Roberson 2015년 8월 13일
Prompt: Write a function called movies that takes the starting times of two movies, hr1, hr2, min1, min2, and their durations, durmin1, durmin2, as its input arguments and decides whether we can binge and watch both. The criteria are that they must not overlap and that we are not going to wait more than 30 minutes between the end of one and the beginning of the next. It returns true if the criteria are both met and returns false otherwise. You may assume that movie start times are always after 1 pm and before midnight. You may also assume that the first one starts earlier. The order of the input arguments is: hr1, min1, durmin1, hr2, min2, durmin2.
Proposed solution:
function m = movies(hr1,min1,durmin1,hr2,min2,durmin2)
m1=hr1*60+min1;
m2=hr2*60+min2;
d1=m1+durmin1;
d2=m2+durmin2;
e=sum((m2-d1)==(1:30));
if e==1
m=true;
else
m=false;
end
The grader tells me it makes an error computing the input: movies(1,0,90,2,30,60) despite the fact that when I enter that input, it works just fine.
Any advice would be much appreciated.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 13일
Your code checks for a difference of 1 minute to 30 minutes. Your code does not test for the possibility that the gap is 0 minutes.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by