Help with correct loop logic

I am having problems with my hangman program. I need to have the board displayed for each guess the player makes, if the answer is correct the board does not change. If the answer is incorrect the board will change. I tried to do the loop so that when the user makes 6 wrong guesses the final board will be displayed meaning the player lost the game. Here is my code so far...

[#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;

const string boardOne = " ------|\n | |\n |\n |\n |\n -------\n\n";
const string boardTwo = " ------|\n | |\n 0 |\n |\n |\n -------\n\n";
const string boardThree = " ------|\n | |\n 0 |\n | |\n |\n -------\n\n";
const string boardFour = " ------|\n | |\n 0 |\n-| |\n |\n -------\n\n";
const string boardFive = " ------|\n | |\n 0 |\n-|- |\n |\n -------\n\n";
const string boardSix = " ------|\n | |\n 0 |\n-|- |\n \\ |\n -------\n\n";
const string boardSeven = " ------|\n | |\n 0 |\n-|- |\n/ \\ |\n -------\n\n";

int main()
{
// Declarations
string fileWord;
ifstream inFile;
int wrongGuess = 0;
char letterGuess = 0;



// while loop to get the last word from file
inFile.open("hangman.dat");
while (!inFile.eof())
{
cout << fileWord << endl;
inFile >> fileWord;
}

inFile.close();

//capitalize the word to use in the game of hangman
std::transform(fileWord.begin(), fileWord.end(), fileWord.begin(), toupper);
cout << "\nWord to Guess: " << fileWord << endl;

cout << "\n" << boardOne << endl;

while (wrongGuess != 6)
{
cout << "\nEnter a letter to guess: ";
cin >> letterGuess;
letterGuess = toupper(letterGuess);
cout << "You guessed the letter: " << letterGuess << endl;
bool found = false;

for (int i = 0; i < fileWord.length(); i++)
{
if (fileWord[i] == letterGuess)
{
cout << "\n" << letterGuess << " is in the letter to guess." << endl;
found = true;
}

}
// if not found - increment wrong guesses
if (!found)
{
wrongGuess++;
cout << "\n" << letterGuess << " is not in the word to guess." << endl;
//print the board that corresponds to the wrongGuess

if (wrongGuess = 0)
cout << boardOne << endl;
if (wrongGuess = 1)
cout << boardTwo << endl;
if (wrongGuess = 2)
cout << boardThree << endl;
if (wrongGuess = 3)
cout << boardFour << endl;
if (wrongGuess = 4)
cout << boardFive << endl;
if (wrongGuess = 5)
cout << boardSix << endl;
if (wrongGuess = 6)
cout << boardSeven << endl;
}
}


cout << "\n\n";
system("pause");
return 0;
}
}
Topic archived. No new replies allowed.