Hangman game with word bank input from .txt file

I am trying to pull my words randonly from a wordbank .txt file and so far i have this

#include <iostream>
#include <cctype>
#include <fstream>

using namespace std;

string word;
char knownLetters[]; // The word could be of any length
int stages = 6; // Our hangman has 6 stages, so the player starts with 6 lives
bool running = 1;

void printStage(int)
void printWord(char[],char[])
void printLettersGuessed(bool[],char[])

int main()
{
char userGuess
ofstream myfile ("WordBank.txt");
if (myfile.is_open() )
{
do
{
myfile << endl;
myfile.close();
cout << "Guess a letter: ";
cin >> userGuess;
bool correct = 0;

for(int pos = 0; pos < 15; pos++) {
if(userGuess == word[pos]) {
knownLetters[pos] = userGuess; // If the letter is in the word, mark it as guessed
correct = 1;
}
}
if(correct == 0) stages--; // If the letter was wrong, subtract a life
correct = 0;
printStage();
PrintLetters();
while(running)
}
return 0;
}
cout << "a word could not be found in the word bank, or it does not exist.";
return 0;
}

void printStage(int)
{
switch(stages) {
case 6:
cout << " +-----+" << endl;
cout << " : :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << "--------------";
break;
case 5:
cout << " +-----+" << endl;
cout << " : :" << endl;
cout << " : 0" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << "--------------";
break;
case 4:
cout << " +-----+" << endl;
cout << " : :" << endl;
cout << " : 0" << endl;
cout << " : :" << endl;
cout << " : :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << "--------------";
break;
case 3:
cout << " +-----+" << endl;
cout << " : :" << endl;
cout << " : 0" << endl;
cout << " : :" << "\\" << endl;
cout << " : :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << "--------------";
break;
case 2:
cout << " +-----+" << endl;
cout << " : :" << endl;
cout << " : 0" << endl;
cout << " : "<< "/" << ":" << "\\" << endl;
cout << " : :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << "--------------";
break;
case 1:
cout << " +-----+" << endl;
cout << " : :" << endl;
cout << " : 0" << endl;
cout << " : " << "/" << ":" << "\\" << endl;
cout << " : :" << endl;
cout << " : " << "\\" << endl;
cout << " :" << endl;
cout << " :" << endl;
cout << "--------------";
break;
case 0:
cout << " +-----+" << endl;
cout << " : :" << endl;
cout << " : 0" << endl;
cout << " : " << "/" << ":" << "\\"<< endl;
cout << " : :" << endl;
cout << " : " << "/" << " \\" << endl;
cout << " :" << endl;
cout << " : DEAD!" << endl;
cout << "--------------";
return;

}

void printWord(char[],char[])
{
for(int pos = 0; pos < word.length(); pos++) {
if(knownLetters[pos] == word[pos]) cout << word[pos];
else cout << "_";
}

void printLettersGuessed(bool[],char[])
{

}


Can someone help me with my errors?
Last edited on
i was also given the parameters of using an array to switch lowercase inputs to uppercase, and to create an array for the inputs that match the wordbank pool.
Topic archived. No new replies allowed.