please include a copy code thanks 15. Number guessing game. Write a program, gue
ID: 3935491 • Letter: P
Question
please include a copy code thanks 15. Number guessing game. Write a program, guessing.m, that does the following: The computer generates a random integer between 1 and 20 (inclusive). The computer displays "T am thinking of a number between 1 and 20." It prompts the user to input a guess. While the guess is not equal to the computer's number, it tells the user whether the guess was too low or too high, and prompts for another guess. When the user guesses the right number the computer congratulates the user and ends the game. (Hint: Use a while loop.) A run of the program (for which the user guessed 10 and 15 before correctly guessing 13) might look something like this: >> guessing I am thinking of a number between 1 and 20. Enter your guess: 10 Too 1ow Enter your guess: 15 Too high Enter your guess: 13 Right!Explanation / Answer
function [] = guessing()
fprintf('I am thinking of a number between 1 and 20. ');
number = ceil( rand*20 );
while 1
guess = input('Enter your guess: ');
if guess == number
fprintf('Right! ');
break;
elseif guess > number
fprintf('Too high ');
else
fprintf('Too low ');
end
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.