Write a function named guessme. The function should ask you to guess a number between 1 and 100. The function should allow three attempts to guess the number. It should respond with \'Guess a lower number\', \'Guess a higher number\',\'YOU WIN !!!\',or \'No, the number is __\' . Use rng(\'shuffle\') and randi() to generate the number.
Solution
% This is a guessing game
counter=0;
real_number=rand(1);
real_number=100*real_number;
number=ceil(real_number);
fprintf(\'I am thinking a number between 1 and 100.\ \');
guess=input(\'Guess a number: \');
while guess~= number
counter = counter + 1;
if guess>number
fprintf(\'Your guess is too high!\ \');
guess=input(\'Guess another number: \');
else
fprintf(\'Your guess is too low!\ \');
guess=input(\'Guess another number: \');
end
end
counter= counter + 1;
fprintf(\'Congratulations! You guessed the correct number in %g shots. \ \', counter);
.