Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create and use programmer-defined functions Implement pseudo-random numbers Practice constructing repetition using both counters and sentinels Tasks Create a new C++ program in the IDE
- Create and use programmer-defined functions
- Implement pseudo-random numbers
- Practice constructing repetition using both counters and sentinels
Tasks
- Create a new C++ program in the IDE of your choice
- Replace the contents of the shell program with our class template and update the header information
- Write pseudocode (or a flowchart) and a C++ program to play a "guess the number" game with the user:
- As the user for the range they wish to use for the random number (they will have to enter the low and the high end of the range)
- The program randomly picks a number in the range specified by the user (inclusive)
- The user has 5 tries to guess the number
- Print a message saying if the guess is too high or too low
- If the user guesses the correct number, they win the game and it's over
- If the user doesn't guess within 5 tries, they lose the game; print out what the number was
- Ask the user if they want to play again and repeat if they do (make sure to get a new range and pick a new random number!)
- Requirement: You must create a programmer-defined function that picks a random number given a specified range. This function should be called to pick the random number for the game.
- Requirement: You must use a global constant to define the number of guesses allowed. All other variables should be local.
- Requirement: You must use repetition to control the five guesses.
Sample Output
Welcome to Guess the Number! I will let you pick the range for the mystery number. What is the low end of the range? 0 What is the high end of the range? 10 Got it, I will pick a number between 0 and 10 (inclusive). I've got one! Try and guess it. 5 Nope, that's too low. Guess again. 7 Nope, that's too high. Guess again. 6 You're a mind reader! The mystery number was 6. Do you want to play again? (y for yes or n for no) y I will let you pick the range for the mystery number. What is the low end of the range? 0 What is the high end of the range? 20 Got it, I will pick a number between 0 and 20 (inclusive). I've got one! Try and guess it. 10 Nope, that's too low. Guess again. 12 Nope, that's too low. Guess again. 14 Nope, that's too low. Guess again. 16 Nope, that's too low. Guess again. 18 Sorry, you're out of guesses! The mystery number was 19. Do you want to play again? (y for yes or n for no) n Ok, see you again soon!
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