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 = 0;
}
int i = 0;
int numberOfWrongAns = 0;
while (1)
{
if (numberOfWrongAns == 0)
{
cout <>
}
else if (numberOfWrongAns == 1)
{
cout <>
}
else if (numberOfWrongAns == 2)
{
cout <>
}
else if (numberOfWrongAns == 3)
{
cout <>
}
else if (numberOfWrongAns == 4)
{
cout <>
}
else if (numberOfWrongAns == 5)
{
cout <>
}
else if (numberOfWrongAns == 6)
cout <>
break;
}
cout < "enter="" a="" letter="" to="" guess:="">
cin >> c;
cout < "you="" entered:"="">< c=""><>
bool flag = false;
for (int j = 0; j < n;="">
{
if (c == word[j])
{
flag = true;
ar[j]++;
if (ar[j] == 1)
{
i++;
}
cout < c="">< "="" is="" in="" the="" word="" to="">
break;