hangman project please help

hello guys I really need you guys help I did this programming project but there is something wrong with it and I honestly can't figure out what the problem is. the program reads the words from a txt file. but I can't make it work. all this c++ thing is new for me so I would really appreciate if someone helps me.
#include<iostream>
#include<string>
#include<stdlib.h>
#include<cmath>
#include<time.h>
#include<fstream>
#include <algorithm>
#include <cctype>


using namespace std;

string THE_WORD; // word to guess
int wrong= 0;
string soFar;
string used;
int playGame(string word);
string getWord();
char askGuess(string usedLettersStr); //tells the compiler of method askGuess
bool playAgain();

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



string word = getWord();

cout<<"Welcome to the hangman game.Good luck!"<<endl;

do
{
const int MAX_WRONG = 6;

while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
{
cout << "\n\nYou have " << (MAX_WRONG - wrong) << " incorrect guesses left.\n";
cout << "\nYou've used the following letters:\n" << used << endl;
cout << "\nSo far, the word is:\n" << soFar << endl;

used += askGuess(used);





// end of while ((wrong < MAX_WRONG) && (soFar != THE_WORD))
}

if (wrong == MAX_WRONG)
{
cout << "\nYou've been hanged!";
}

cout<< "You missed "<<playGame(word);
cout<<" times to guess the word."<<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;
}
Last edited on
Topic archived. No new replies allowed.