Source Code
Source Code
#include <iostream.h>
#include <cstdlib.h>
#include <ctime.h>
#include <string.h>
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[] =
{
"mango",
"pineapple",
"banana",
"watermelon",
"strawberry",
"apple",
"kiwi",
"raspberry",
"orange",
"pear"
};
srand(time(NULL));
int n=rand()% 10;
word=words[n];
string unknown(word.length(),'*');
cout << "\n\n Welcome to hangman...Guess a Fruit Name";
cout << "\n\n Each letter is represented by a star. ";
cout << "\n\n You have to type only one letter in one try";
cout << "\n\n You have " << MAX_TRIES << " tries to try and guess the word. ";
cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
while (num_of_wrong_guesses < MAX_TRIES)
{
cout << "\n\n" << unknown;
cout << "\n\n Guess a letter: ";
cin>> letter;