Write a Guess My Number Game program The program generates a

Write a \"Guess My Number Game\" program. 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 as follows. The program starts by printing instructions on the screen. For every game: the program generates a new random integer in the range from MIN to MAX. Treat MIN and MAX like constants; start by initializing them to 1 and 100 loop to prompt the player for a guess until the player correctly guesses the integer for each guess, the program prints whether the player\'s guess was too low, too high, or correct. At the conclusion (when the integer has been guessed): print the total number of guesses for that game. print a message regarding how well the player did in that game (e.g., the Player took way too long to guess the number, the player was awesome, etc.); to do this, you will have to decide on ranges for your messages and give a rationale for your decision in a comment in the program. After all games have been played, print a summary showing the average number of guesses.

Solution

clear all fprintf(\'\ welcome to guess my number game\') disp(\' \') a = input(\'\ Please tell me you nice Name : \',\'s\'); fprintf(\'\ \\t Welcome to the game %s\',a) disp(\' \'); m1 = 1; while m1 == 1 disp(\' \'); disp(\'Choose the level of playing:\') disp(\'1) 1-10\') disp(\'2) 1-100\') disp(\' \') o = input(\'enter the level you want to play: \'); disp(\' \') switch o case 1, n = 10; case 2, n = 100; end b = randperm(n); index = randperm(length(b)); r = b(index(1)); m2 = 1; count = 0; while m2 == 1 guess=\'r\'; while guess == \'r\' guess = input(\'Input your guess: \',\'s\'); end guess = str2num(guess); if (guess == r); disp(\' \') fprintf(\'Correct! My secret number was: %i\ \',r) m2 = 2; elseif (guess > n); disp(\' \') fprintf(\'Too high, please less than %i\ \',n) disp(\' \') elseif (g < 1); disp(\' \') disp(\'Too low, please more than %i\ \',n) disp(\' \') elseif (guess > r); disp(\'Lower\') else (guess < r); disp(\'Higher\') end count = count+1; end disp(\' \') fprintf(\'Guesses needed to find my secret number: %i\ \',c) disp(\' \') if (count == 1); disp(\'marvallous\') elseif (count >= 2 && count < 0.5*n); disp(\'excellent\') elseif (count == 0.5*n); disp(\'Avg\') elseif (count > 0.5*n && count <= 0.8*n); disp(\'its very poor\') else (count > 0.8*n); disp(\'better luck next time !\') end disp(\' \') p = input(\'will u wish to play again? (yes/no): \',\'s\'); if p == \'no\' m1 = 2; end disp(\' \') fprintf(\'Thank you very much %s\ \',a) end
 Write a \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site