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 -------|

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

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<iostream>
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;
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY