Part of my program wont work and i just cant figure it out why.
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!