Question: LANGUAGE: C++ COMPILER: Visual Studio Write a number-guessing game in which the computer selects a random number in the range 1 to 100, and users

LANGUAGE: C++

COMPILER: Visual Studio

Write a number-guessing game in which the computer selects a random number in the range 1 to 100, and users get a maximum of 20 attempts to guess it. After each guess there should be some hint given to the player as to how close that guess was. If the guess was only 1 away print a hint like "That guess was hot". If the guess was within 5 points (high or low) print a hint like "You're getting warm". If the guess was within 10 points print a hint like "Your guess is still cool". If the guess was more than 10 points away print a hint like "You're guess is cold". At the end of each game, users should be told whether they won or lost, and how many guesses it took if they got it correct. To make the game more interesting, the program should vary the wording of the messages that it outputs for winning, for losing, and for asking for another game. Create as many as 5 different messages for each of these cases and use random numbers to choose among them. You should put this functionality in two functions called SayYouWon and SayYouLost At the end of each game the player should then be asked if they want to play again. The user should be allowed to play as many games as desired. When the user quits, the program should output the total number of wins and losses. You should create a third function called CheckGuess that takes the player's current guess and the number selected by the computer and prints an appropriate response as described above. It might be useful to have the function return a boolean value; true if the player guessed the number and false if not. You should create a fourth function called GetRandomNumber that generates and returns a random number when passed the range in which to select the random number. To generate a random number, you must include one header file:

#include

You will also need the time header file if you want to use time to seed the random number generator.

#include

Somewhere at the beginning of the program you will need to make one and only one call to the srand function to seed the random number generator. It requires an unsigned int value to be passed to it. The easiest way to ensure that this is a relatively random seed number is to pass in the current time in seconds.

srand((unsigned int)(time(NULL)));

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!