Question
C++ Problem: Implement a guessing game in C++, after each round of playing the game, ask the user if they want to keep going, and
C++ Problem:
Implement a guessing game in C++, after each round of playing the game, ask the user if they want to keep going, and if they give the input 'q' then stop, otherwise continue with a new round of the game.
For each round, the program should choose a random number in the range [0, 99]. You may use the provided function below to get a new number. The program should then continue to prompt the user for a new guess until they find the number. If they find it, print out a congratulatory response and conclude the round. If they do not find it, print out a message indicating whether their guess was low or high and prompt them for another guess. You can see sample output below.
Starter Code:
#include#include #include static int getNumber(); int main() { // TODO: implement the guessing game, you may use 'getNumber()' to get a random number // in the range [0, 99] } static int getNumber() { static std::mt19937 generator{ std::random_device{}() }; static std::uniform_int_distribution range{ 0, 99 }; return range(generator); }
Sample Output:
> I'm thinking of a number in the range [0, 99] try to guess what it is! > Enter a guess: 50 > Too low... > Enter a guess: 75 > Too high... > Enter a guess: 66 > Too high... > Enter a guess: 60 > Too high... > Enter a guess: 55 > Too high... > Enter a guess: 53 > Too high... > Enter a guess: 52 > Congratulations! You found it! > Would you like to play again? (q to quit): y > I'm thinking of a number in the range [0, 99] try to guess what it is! > Enter a guess: 50 > Too high... > Enter a guess: 25 > Too high... > Enter a guess: 12 > Too high... > Enter a guess: 6 > Congratulations! You found it! > Would you like to play again? (q to quit): q
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started