c++ hangman game

I modified my code so it would be simpler I just want to know how would I put a limit so it would only have 6 times to guess if the does guess by the 6 time your dead. how would I put a limit on this code to stop at 6 guesses and anyone help me please.
here is the code
this code works fine but the thing is the it doesn't have a limit to 6 guesses it stop until the word is reveal word by word can anyone help me. but the word are from a text file
her is the code
#include<iostream>
#include<string>
#include<stdlib.h>
#include<cmath>
#include<time.h>
#include<fstream>

using namespace std;

int playGame(string word);
string getWord();

int main()
{
int misses = 0;
srand(time(NULL));



string word = getWord();

cout<<"Welcome to the hangman game."<<endl;
cout<<"You only have 6 time to guess. Good luck!"<<endl;

cout<< "You missed "<<playGame(word);
cout<<" times to guess the word."<<endl;
}

string getWord()
{
fstream inputStream("words.txt");
string input[1000];
int i=0;
while(getline(inputStream, input[i]))
{
i++;
}
string randWord = input[rand()%i + 1];
inputStream.close();
return randWord;

return "hangman";
}

int playGame(string word)
{
int misses = 0;
int exposed = 0;
string display = word;
for(int i = 0; i < display.length(); i++)
display [i] = '*';

while(exposed < word.length())
{
cout<<"Misses "<<misses<<":";
cout<<"Now please choose a letter ";
cout<<display<<" : ";
char response;
cin >> response;

bool goodGuess = false;
bool duplicate = false;
for(int i = 0; i < word.length(); i++)
if(response == word[i])
if (display [i] == word[i]) {
cout<<response<< " is already in the word.\n";
duplicate = true;
break;
}
else{
display[i] = word[i];
exposed++;
goodGuess = true;
}

if(duplicate)
continue;

if(!goodGuess)
{
misses++;
cout<<response<<" is not in the word.\n ";
}
}




cout<<"Word was " <<word<<" . " << endl;
return misses;
}
You could check the current count of misses before starting another run through the loop asking them to enter a character.
Topic archived. No new replies allowed.