Lab 4: Guessing game with loops
Contents
Instructions
This lab has two parts:
Part 1: Lab 3 Redux
For this part, you will update your Lab 3 code so that rather than only give the user 3 guesses, the user has unlimited guesses. Save this lab file as lab4_part1.cpp. The goal is to get the fewest number of guesses.
********************************************************************************
GUESS A NUMBER
********************************************************************************
I'm thinking of a number...okay, got it. I'll give you three guesses as to
what number I have in mind. It's between 1 and 50.
Guess 1: 16
That's too low. Try again.
Guess 2: 35
That's too low. Try again.
Guess 3: 46
That's too high. Try again.
...
Guess 10: 43
That's correct! It took you 10 guesses to find my secret number!
Use a loop to keep prompting the user until they've guessed correctly. Make sure to print out how many guesses it took the user.
Part 2: Input validation
For part 2, you should add input validation to Part 1. Using a separate loop or a carefully placed branch, modify the program so that when a user enters a value that is out side of the range 1--50, it prints an error stating their input is out of range and they are re-prompted without adding to the number of guesses they took. Use constants where appropriate.
Submission
Submit your .cpp files to here. You can view the rubric here.
(Back to top)