Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2) (20 pts) Filename MAE 1090 HW6 2.m Write an m-file that will play the \"Guess

ID: 3802356 • Letter: 2

Question

2) (20 pts) Filename MAE 1090 HW6 2.m Write an m-file that will play the "Guess My Number Game" with the user. The program generates a random integer in a specified range, and the user (the player) has to guess the number. The program allows the user to play as many times as he/she would like; at the conclusion of each game, the program asks whether the player wants to play again The basic algorithm is: (1) Start by printing instructions on the screen. (2) For every game (a) Prompt the user for minimum and maximum values.

Explanation / Answer

c=1;
while c==1
xmin=input('Enter min number: ');
xmax=input('Enter max number: ');
n=ceil(xmin+rand(1)*(xmax-xmin));

g=0;
t=0;

while g ~= n
g=input('Guess the number: ');
t=t+1;
if g < n
disp('Number is less');
elseif g > n
disp('Number is greater');
else
clc;
fprintf('Corect number. It took you %d guesses ', t);

end
end
  
c=input('Do you want to play again! 1 or 0');
  
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote