Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 4 Ott 2019
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

Più risposte (0)

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by