#include <iostream>
#include <cstdlib>
#include<ctime>
#include <string>
using namespace std;
const int MAX_TRIES=5;
int letterFill (char, string,
string&);
int main () {
string name;
char letter;
int num_of_wrong_guesses=0;
string word;
string words[] = {
"india",
"pakistan",
"nepal",
"malaysia",
"philippines",
"australia",
"iran",
"ethiopia",
"oman",
"indonesia"
};
srand(time(NULL));
int n=rand()% 10;
word=words[n];
cout << "\t*** Welcome To
Hangman ***";
cout << "\n\nGuess A Country
Name.\n\nEach Letter Is Represented By A Star.";
cout << "\n\nType Only One
Letter In Every Try.";
cout << "\n\nYou Have "
<< MAX_TRIES << " Tries To Guess The Word.";
cout <<
"\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
while (num_of_wrong_guesses <
MAX_TRIES) {
cout << "\n\n" <<
unknown;
cout << "\n\nGuess A Letter:
";
cin >> letter;
if (letterFill(letter, word,
unknown)==0) {
cout << endl << "Whoops!
Wrong Choice.." << endl;
num_of_wrong_guesses++;
}
else
cout << endl << "You
Found One Correct Letter!" << endl;
cout << "\nYou Have "
<< MAX_TRIES - num_of_wrong_guesses;
cout << " Guesses Left."
<< endl;
if (word==unknown) {
cout << word << endl;
cout << "\nYeah! You Got
It!";
break;
}}
if(num_of_wrong_guesses == MAX_TRIES) {
cout << "\nSorry, You Lost
It... You Have Been Hanged." << endl;
cout << "\nThe Correct Word
was : " << word << endl;
}
cin.ignore();
cin.get();
return 0;
}
int letterFill (char guess, string
secretword, string &guessword) {
int i;
int matches=0;
int len=secretword.length();
for (i = 0; i< len; i++) {
if (guess == guessword[i])
return 0;
if (guess == secretword[i]) {
guessword[i] = guess;
matches++;
}}
return matches;
}