Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 srandfunction 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Shouhong Wang, Hai Wang

1st Edition

1612330150, 978-1612330150

More Books

Students also viewed these Databases questions

Question

=+ Are there additional forms of employee representation?

Answered: 1 week ago