필터 지우기
필터 지우기

Part of my program wont work and i just cant figure it out why.

조회 수: 1 (최근 30일)
Davifus
Davifus 2019년 10월 3일
답변: Walter Roberson 2019년 10월 4일
The question is "The program asks for an input of a score(0-100). If the score is greater than or equal to 60, display “Congratulations! You passed!” Otherwise, display “Sorry, you failed.” "
prompt='score greater than 60 and less than 60'
x=input(prompt)
if x>=60
if x<60
end
if x<60
disp('Sorry, you failed.')
end
end
if x>=60
disp('Congratulations! You passed!')
end
when i run the program i get the "Congratulations! You passed!" for anything above 60 but when i run the program for # less 60 nothing happens. i just get the inputted number back without the disp.

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 4일
Look more carefully at your code. You have
if x>=60
statements between that and the next matching else or elseif or end statement are only executed if x is greater than or equal to 60
if x<60
end
if x<60
disp('Sorry, you failed.')
end
including those ones. You do not reach those statements unles x>=60 and if x>=60 then x<60 cannot possibly be true.
if rand*100 > 60
disp('Hip Hip Ho!')
else
disp('Hop Hep Hey!')
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by