Hangman Game in C++ The instructions are in the pictures. This is what it is supposed to look like: Here is a sample run of the program and what it should look like screen to screen: computer science programming Do you want to play hangman? (y or n): y Let's PLAY Word to Guess: PROGRAMMING -------| | | | | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | | | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | -| | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | -|- | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | -|- | / | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | -|- | / \ | | ----- Sorry you lose - the word was: PROGRAMMING Do you want to play hangman? (y or n): i Error - please enter (y or n) Do you want to play hangman? (y or n): Sure Let's PLAY Word to Guess: SCIENCE -------| | | | | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | | | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | -| | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | -|- | | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | -|- | / | | ----- Enter a letter to guess: w You entered: W W is NOT in the word to guess. -------| | | O | -|- | / \ | | ----- Sorry you lose - the word was: SCIENCE Do you want to play hangman? (y or n): u Error - please enter (y or n) Do you want to play hangman? (y or n): NO Goodbye This is what I have so far but I can't get it to work or to the final product: #include using namespace std; int main() { string BOARD1 = " -------|\n | |\n |\n |\n |\n |\n -----\n"; string BOARD2 = " -------|\n | |\n O |\n |\n |\n |\n -----\n "; string BOARD3 = " -------|\n | |\n O |\n | |\n |\n |\n -----\n"; string BOARD4 = " -------|\n | |\n O |\n -| |\n |\n |\n -----\n"; string BOARD5 = " -------|\n | |\n O |\n -|- |\n |\n |\n -----\n"; string BOARD6 = " -------|\n | |\n O |\n -|- |\n / |\n |\n -----\n"; string BOARD7 = " -------|\n | |\n O |\n -|- |\n / \\ |\n |\n -----\n"; string word; cout << "Enter a letter to guess: "; cin >> word; int n = word.size(); char c; int ar[n + 1]; for (int i = 0; i < n; i++) { i = 0; } int i = 0; int numberOfWrongAns = 0; while (1) { if (numberOfWrongAns == 0) { cout << BOARD1; } else if (numberOfWrongAns == 1) { cout << BOARD2; } else if (numberOfWrongAns == 2) { cout << BOARD3; } else if (numberOfWrongAns == 3) { cout << BOARD3; } else if (numberOfWrongAns == 4) { cout << BOARD5; } else if (numberOfWrongAns == 5) { cout << BOARD6; } else if (numberOfWrongAns == 6) cout << BOARD7; break; } cout << "Enter a letter to guess: "; cin >> c; cout << "You entered:" << c << "\n\n"; bool flag = false; for (int j = 0; j < n; j++) { if (c == word[j]) { flag = true; ar[j]++; if (ar[j] == 1) { i++; } cout << c << " is in the word to guess\n"; break;
Hangman Game in C++
The instructions are in the pictures. This is what it is supposed to look like:
Here is a sample run of the program and what it should look like screen to screen:
computer
science
Do you want to play hangman? (y or n): y
Let's PLAY
Word to Guess: PROGRAMMING
-------|
| |
|
|
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
|
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
| |
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
-| |
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
-|- |
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
-|- |
/ |
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
-|- |
/ \ |
|
-----
Sorry you lose - the word was: PROGRAMMING
Do you want to play hangman? (y or n): i
Error - please enter (y or n)
Do you want to play hangman? (y or n): Sure
Let's PLAY
Word to Guess: SCIENCE
-------|
| |
|
|
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
|
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
| |
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
-| |
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
-|- |
|
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
-|- |
/ |
|
-----
Enter a letter to guess: w
You entered: W
W is NOT in the word to guess.
-------|
| |
O |
-|- |
/ \ |
|
-----
Sorry you lose - the word was: SCIENCE
Do you want to play hangman? (y or n): u
Error - please enter (y or n)
Do you want to play hangman? (y or n): NO
Goodbye
This is what I have so far but I can't get it to work or to the final product:



Trending now
This is a popular solution!
Step by step
Solved in 2 steps









