Question: Guessing Game #include #include #include using namespace std; int main() { int num; // holding a random number generated by computer int guess; // holds

Guessing Game

#include #include #include using namespace std; int main() { int num; // holding a random number generated by computer int guess; // holds the guess of the user bool isGuessed; // true if user guessed the number correctly srand(time(0)); // initialize randomness with time num = rand() % 100; // ensure the number is 0 to 100 isGuessed = false; cout > guess; if (guess == num) { cout num) { cout

Guessing Game #include #include #include using namespace std; int main() { int

num; // holding a random number generated by computer int guess; //

First, copy the above code into visual studio, compile, run and enjoy playing the game a little ) Step #2: Modify the program so that in the end (with "You got it!!" message), it would also tell the user in how many tries he/she found the right number. Hint: you need a variable to hold the number of tries, and this variable should be incremented by one at each try. you simply output that variable as the user found the number in that many tries Step #3: Modify this program so that user gets at most 6 tries. If not guessed in 6 tries, program should indicate that user has lost the game and exits -- you probably want to use "break" statement to exit out of the loop if the count is higher then limit Step #4: Currently program only tells the user if the quess is high or low. Modify this program so that it would give an indication of how high or how low the guess is. If the guess is more than 50 above or below the number, output "Way too high" or "Way too low". If less than 15, "High, but getting closer" or "Low, but getting closer". Notice that for between 15 and 50, we simply provide the default message. you can play around with these messages, this is provided as an example. My suggestion on this step is to create a new variable that would keep the difference between the guessed number and the target number. Let's call it diff. So declare diff at the beginning of your program and then set its value after getting the guess from user. At this point you need to change the if statements. I think you got the idea :-)) Step #5: Modify the program so that it does not exit after each game, but instead asks the user if he/she wants to play again. Step #6 Modify the program so that it would keep a high score. Highest score is the least amount of tries to find the target number. One way to handle this would be to declare a variable that would hold the high score. Let's call this variable highscore After each successful guessing of the target number, we should check number of tries to the high score, if lower, new high score is set to the number of tries in that game. usst he umer of tis i taga That's it

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!