Professional Documents
Culture Documents
Hangman Pakibago
Hangman Pakibago
#include <cstdlib>
#include <conio.h>
#include <string>
using namespace std;
void game(string word, int&status);
int main()
{
string a = " ";
string confirm = " ";
int status = 0;
do
{
system("cls");
cout << "Enter a word! ";
getline(cin, a);
cout << "Changed your word? (YES or NO) ";
cin >> confirm;
if (confirm == "NO")
{
break;
}
} while(1);
game(a, status);
if (status == 1)
{
cout << "Congratulations! ";
system("pause");
}
else
{
cout << "Game over! ";
system("pause");
}
}
do
{
system("cls");
string input;
int left = 0;
cout << "Guess the word! " << b << endl << "Enter a letter: ";
cin >> input;
if (input.length() != 1)
{
cout << "Hey! No entering words! ";
system("pause");
continue;
}
int counter = 0;
int g = 0;
int h = 0;
for (int i = 0; i < word.length(); i+=g)
{
string s = word + input;
g = s.find(input, g) + 1;
h = g - 1;
if (g != s.length())
{
b = b.replace(h, 1, input);
counter = 1 + counter;
}
else
{
break;
}
}
cout << "Number of present letters: " << counter << endl;
if (counter == 0)
{
life -= 1;
}
cout << life << " remaining lives. ";
system("pause");
//checking
string p = b + "_";
left = p.find("_") + 1;
if (left == p.length())
{
status = 1;
break;
}
else if (life == 0)
{
break;
}
else
{
continue;
}
} while (life > 0);
}