Question: This is using MARS (MIPS Simulator) Lets practice our control flow with a simple game. Your task is to write a program that generates a

This is using MARS (MIPS Simulator)

Lets practice our control flow with a simple game. Your task is to write a program that generates a random number between 0 and 99 (inclusive), then ask user to guess it. If the user gets it right, congratulate them. They have won and the game ends. Otherwise, you should tell them whether their number is too high or too low and let them guess again. You should say they are warm when the guessed number is within 10 of the correct number and cold otherwise.

For example, if the number is 53, any guess that was between 44 to 62 inclusive would report being warm. Otherwise, it would say Youre cold.

The user is allowed to guess at most five times. If the user cannot get it right after the fifth time, they have lost and they game ends. Make sure to prompt the user with a message and explain whether their guess is correct, too low, too high, and also warm, cold, etc.

I believe, after doing some napkin-math, that with seven guesses you can always get the right answer. You certainly can with eight. So, were being a little evil here by making the guess count 5. >:}

The output should look something like:

Enter a number between 0 and 99: 50 Your guess is too high. You're cold. Enter a number between 0 and 99: 25 Your guess is too high. You're cold. Enter a number between 0 and 99: 12 Your guess is too high. You're warm! Enter a number between 0 and 99: 8 Your guess is too low. You're warm! Enter a number between 0 and 99: 10 Your guess is too low. You're warm! You lose. The number was: 11 -- program is finished running -- 
Enter a number between 0 and 99: 50 Your guess is too low. You're cold. Enter a number between 0 and 99: 80 Your guess is too low. You're cold. Enter a number between 0 and 99: 95 Congratulations! You win! -- program is finished running --

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!