Question
Please write a C++ program to simulate a simple version hangman game. In this game, a well-known phrase is hidden in the beginning. The user
Please write a C++ program to simulate a simple version hangman game. In this game, a well-known phrase is hidden in the beginning. The user tries to guess that phrase by guessing letters. For example if the phrase is Hello World, the user will see the hidden version where every character is replaced with _ such as
_ _ _ _ _ _ _ _ _ _
The user will guess letters in the phrase, and he/she has total of 10 tries to successfully reveal the phrase. If the guessed letter is not in the phrase, the number of tries will be decreased. Otherwise it will not be changed. For example, if the user guesses the letter o, your program will print the phrase with os.
_ _ _ _ o _ o _ _ _
If the user guesses all letters in the phrase correctly before 10 tries, he/she wins the game. Otherwise he/she loses the game.
In the beginning of your program, the phrase is selected randomly from an array of strings. Fill your array with following 5 phrases:
1 | Back to Square One |
2 | Easy As Pie |
3 | Elephant in the Room |
4 | Fish Out Of Water |
5 | Needle In a Haystack |
The user may enter lower case or upper case of the correct letter. So you must consider both cases and accept if the letter matches.
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