Question: Here is the question:::: Write a MatLab program GuessNumber.m . The program randomly generates an integer between 1 and 1000, and asks the user (i.e.,
Here is the question::::
Write a MatLab program GuessNumber.m. The program randomly generates an integer between 1 and 1000, and asks the user (i.e., the person who runs the program) to guess what the integer is. The program lets the user key in her guess, compares the guess with the randomly generated integer, and shows one of the following messages depending on the difference between them.
If the guess is larger than the integer by more than 100, the program shows information Too large.
If the guess is larger than the integer by more than 10 and no more than 100, the program shows information Close. Make it smaller.
If the guess is larger than the integer by no more than 10, the program shows information Very close now. Make it a little smaller.
If the guess is smaller than the integer by more than 100, the program shows information Too small.
If the guess is smaller than the integer by more than 10 and no more than 100, the program shows information Close. Make it larger.
If the guess is smaller than the integer by no more than 10, the program shows information Very close now. Make it a little larger.
If the guess matches the integer, the program shows Yes! You guessed it.
I already wrote most of the program its jst that i am still stuck and need some to give me an input. I am guessing my inequalities are not right?
here is the program that i wrote
A=randi(1000);
fprintf('I have a number between 1 and 1000. ');
G=input('guess a number between 1 and 1000 and enter it:');
if G>(A+100);
fprintf('Too large. '); %good
elseif G<(A+100);
fprintf('Too small. '); %good
elseif G>(A+10)
fprintf('close. make it smaller. ');
elseif G>(A+10);
fprintf('close. make it a little smaller. ');
elseif G<(A+10);
fprintf('very close. make it a little larger. ');%good
else
fprintf('Yes, you guessed it. ');
end
fprintf('Random interger A is: %.2f ',A);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
