Question: Write a Guessing Game C + + #include #include #include using namespace std; int main ( ) { srand ( time ( 0 ) )

Write a Guessing Game C++
#include
#include
#include
using namespace std;
int main()
{
srand (time(0));
char choice;
int range, guessedNumber =0, Totaltries =1;
cout << "Welcome to the guessing game!
";
cout << "I'll choose a number between 1 and a limit of your choice, "
<< "and you guess what it is.
";
cout << "How high would you like the guessing range to be?";
cin >> range;
int bestscore =0;
do
{
int number = rand()% range +1;
cout <<"I'm thinking of a number! What is it?";
cin >> guessedNumber;
while (guessedNumber != number)
{
if (guessedNumber < number)
{
cout << "Woopsies that's too low. Try again: ";
cin >> guessedNumber;
}
else if (guessedNumber > number)
{
cout << "Dang, that's too high. Try again: ";
cin >> guessedNumber;
}
Totaltries ++;
}
cout << "You guessed it! It took "<< Totaltries <<" tries.
";
Totaltries =1;
if (bestscore > Totaltries )
{
bestscore = Totaltries;
cout <<"***You've set a new record for the lowest number of guesses! ***
";
}
cout << "Would you like to play again? Y/N: ";
cin >> choice;
}while (choice =='Y'|| choice =='y');
return 0;
}
Instead of 1-50, let the user choose the upper guessing limit.
2. Keep track of the number of tries that it took for the user to get the right answer and
display that to them once theyve guessed the correct answer.
3. Add the ability for the user to play again without having to restart the game.
4. Keep track of an overall low score (the lower the number of guesses, the better). If the
user beats the current best score, display a message to them telling them so, and set the
overall low score to be the number of guesses it took from that round.
How can I fix my code?

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 Programming Questions!