You are on page 1of 2

#include <iostream>

#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");
}
}

void game(string word, int&status)


{
string b = word + " "; /* indicator yung space ng end nung word */
int space1 = 0, space2, life = 5;
do
{
space2 /* to what space */ = b.find(" ", space1);
for (int i = space1; i < space2; i++)
{
b = b.replace(i, 1, "_");
}
space1 /* from what space (initially = 0) */ = space2 + 1;
} while (space1 != b.length());
/* hindi siya titigil hangga't hindi equal 'yung haba nung word sa number
value ng end ng word */

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);
}

You might also like