% 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
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, Plagiarism free, and by an EXPERT!
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