Hello everyone, im starting with matlab, and i have a little problem if someone wants to help me it will be nice here is the problem:
A little guessing game works like this: The first player enters a number secret. The second player must guess this number. To do this, he enters a number and then the program tells him if the number to guess is greater or less than the number he suggested. he can keep entering numbers until the secret number is found. In this case, the program displays the number of tries that were required to find the secret number. If the number has not yet been found after 15 attempts, the number to guess is displayed and the program ends. Carry out this program. For interaction with the user, you can use the msgbox functions and inputdlg.
Well my code that im trying is here:
clear all;
close all;
secretnumber=str2double(inputdlg('Enter your secret number','secretnumber'));
number1=str2double(inputdlg('Enter your guess','number1'));
while number1>secretnumber
uiwait(msgbox('Your guess is higher than the secret number, try again','modal'));
str2double(inputdlg('Enter your guess','number1'));
if number1<secretnumber
uiwait(msgbox('Your guess is lower than the secret number, try again','modal'));
str2double(inputdlg('Enter your guess','number1'));
break
end
end
here i am for now, i don't understand why when the value of number1 is smaller than the secretnumber; this code won't execute:
if number1<secretnumber
uiwait(msgbox('Your guess is lower than the secret number, try again','modal'));
str2double(inputdlg('Enter your guess','number1'));
break
end
Thanks a lot, if you have any hint for the msgbox to appear when the number1 is the same as the secret number, i'm taking it thanks.
1 Comment
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/652573-confusion-while-break-continue#comment_1144723
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/652573-confusion-while-break-continue#comment_1144723
Sign in to comment.