 # Answered! Write a Matlab/Excel program that will play a guessing game. Have the computer generate a random whole number…

Write a Matlab/Excel program that will play a guessing game. Have the computer generate a random whole number between 1 and 100. You can do this through the rand command. The user will guess a number and the computer will tell them if they are too high or too low. The program should stop if a correct guess if given. It should also display how many guesses were needed.

The Matlab/Excel program that will play a guessing game.which is Having the computer generate a random whole number between 1 and 100. You can do this through the rand command. The user will guess a number and the computer will tell them if they are too high or too low. The program should stop if a correct guess if given. It should also display how many guesses were needed. and the code is given below.

% program that generates a random numbers between 1 and 100
% user will be given 3 chances to guess it.
nr = randi([1,100]);
i = 0;
choice = input(‘Guess the number(you will be having 3 chances so pick the correct one): ‘);
while choice ~= nr
i = i+1;
if i<3
% choice = input(sprintf(‘You are having only %d more guesses! ‘, i));
else
fprintf (‘Its WRONG buddy please try again! The number was %dn’, nr)
break
end
end
if choice == nr
fprintf(‘Congratulations, you guess was correct and the number is %d!n’, nr)
end

Don't use plagiarized sources. Get Your Custom Essay on
Answered! Write a Matlab/Excel program that will play a guessing game. Have the computer generate a random whole number…
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

Sample Output :

Guess the number(you will be having 3 chances so pick the correct one): 25
Congratulations, you guess was correct and the number is 25