Number guessing function using while and if else functions
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
while x>a || x<a
%This classifies the user's input if the guess is above or below the program will tell the user their guess is incorrect
if x>a || x<a
%This classifies the user's input if the guess is above or below the program will tell the user their guess is incorrect
disp('You are to high/low please guess again \n')
else x=a
disp('You''ve got it!')
end
I'm wanting to run a program that uses a random number and outputs if the user defined input is a correct guess or else the program prompts the user to keep inputting guesses until they are correct.
5 Kommentare
Walter Roberson
am 23 Mär. 2019
else x > a
means the same thing as
else
disp(x > a)
Both branches of your code talk about the person being too high, with no branch saying they are too low.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!