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 Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by