Question: I had to write a matlab program guessing a number between 1 and 1000 in a while loop. i successfully did so. My struggle now

I had to write a matlab program guessing a number between 1 and 1000 in a while loop. i successfully did so. My struggle now is prompt the user to a second round of the game in a while loop format. how can i do that? here is the program

A=randi(1000);

fprintf('I have a number between 1 and 1000. ');

counter=0;

finish = false;

while finish==false

G=input('guess a number between 1 and 1000 and enter it:');

counter = counter+1;

if (G-A)>=100

fprintf('Too large. '); %good

elseif and((G-A)>10,(G-A)

fprintf('close. make it smaller. ');

elseif and((G-A)A));

fprintf('very close now. make it a little smaller. ');

elseif(A-G)>100

fprintf('Too small. '); %good

elseif and(A-G>10,(A-G)

fprintf('close. make it larger. ');

elseif and((A-G)G));

fprintf('very close. make it a little larger. ');%good

else

fprintf('Yes, you guessed the correct in %d shots. ',counter);

finish=true;

end

endI had to write a matlab program guessing a number between 1

Requirement: Further improve your MatLab program GuessNumber.m. The program in step 2 terminates after the user provides a guess matching the integer. If the user wants to play another round, she must execute the program again. In this step, after the improvement, your program can allow the user to continue playing after each round without re-executing the program. Specifically, after each round, the user is asked whether she wants to play another round or not. If the answer is yes (Y), the program generates another random integer and asks the user to make guesses. Otherwise, the program terminates With the program in step 2, the user has to keep guessing until the integer is guessed. With another improvement, the program in this step will allow user to start another round without finishing the current round (i.e., the user has not guessed the integer generated for this round). Specifically, if the user provides a non-positive guess (0 or negative), the program finishes this the existing round and starts a new round. Sample Inputs and outputs: GuessNumber I have a number between 1 and 1000 Guess what it is: 500 Too small Guess what it is: 750 Too big Guess what it is: 625 Very close now. Make it a little bit larger. Guess what it is: 630 Very close now. Make it a little bit larger. Guess what it is: 633 Yes! You guessed the integer in 5 shots My number is 633 Do you want to play one more round? (Y/N) Y I have a number between 1 and 1000

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!