I need some help keeping track of letters the user inputs. With my current code it only outputs one letter at a time of the word to be guessed. Can anyone help?
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <time.h>
using namespace std;
void Hangman();
void LeftArm();
void Head();
void RightArm();
void Body();
void LeftLeg();
void Gallows(int count);
void DisplayAWord(string guessword);
void revealword(char letter, int position,string fileword, string guessword);
void secret(string fileword);
void hidden (string fileword);
char Question ();
int main()
{
srand(time(NULL));
int x = rand()%10 +1;
int count = 0;
int position;
char letter;
ifstream words;
string guessword, fileword;
words.open("words.txt");
do{
words>> fileword;}
while ( --x >= 0 );
secret(fileword);
while (guessword != fileword && count < 6){
letter = Question();
position = fileword.find(letter);
if (position > fileword.length()){
cout<<"There is no "<<letter<< "\n";
count++;
Gallows(count);}
else {
cout<< letter << " is in the "<<position<<"th place\n";
string guessword;
revealword(letter, position, fileword, guessword);
DisplayAWord(guessword);
}
}
if (count >= 6)
cout<<"Gameover man!\n";
cout<<"The word was "<<fileword<< ".\n";
false;
return 0;
}
void LeftArm()
{
cout << setw(8) <<"____" << endl;
cout << setw(4) <<"|" << setw (5) << "}" << endl;
cout << setw(4) <<"|" << setw(4) << "\\" << endl;
cout << setw(4) <<"|" << endl;
cout << setw(4) <<"|" << endl;
cout <<"___|________" << endl;
}
void Head()
{
cout << setw(8) <<"____" << endl;
cout << setw(4) <<"|" << setw (5) << "}" << endl;
cout << setw(4) <<"|" << setw(5) << "\\0" << endl;
cout << setw(4) <<"|" << endl;
cout << setw(4) <<"|" << endl;
cout <<"___|________" << endl;
}
void RightArm()
{
cout << setw(8) <<"____" << endl;
cout << setw(4) <<"|" << setw (5) << "}" << endl;
cout << setw(4) <<"|" << setw(6) << "\\0/" << endl;
cout << setw(4) <<"|" << endl;
cout << setw(4) <<"|" << endl;
cout <<"___|________" << endl;
}
void Body()
{
cout << setw(8) <<"____" << endl;
cout << setw(4) <<"|" << setw (5) << "}" << endl;
cout << setw(4) <<"|" << setw(6) << "\\0/" << endl;
cout << setw(4) << "|" << setw(5) << "|" << endl;
cout << setw(4) <<"|" << endl;
cout <<"___|________" << endl;
}
void LeftLeg()
{
cout << setw(8) <<"____" << endl;
cout << setw(4) <<"|" << setw (5) << "}" << endl;
cout << setw(4) <<"|" << setw(6) << "\\0/" << endl;
cout << setw(4) << "|" << setw(5) << "|" << endl;
cout << setw(4) << "|" << setw(4) << "/" << endl;
cout <<"___|________" << endl;
}
void Hangman()
{
cout << setw(8) <<"____" << endl;
cout << setw(4) <<"|" << setw (5) << "}" << endl;
cout << setw(4) <<"|" << setw(6) << "\\0/" << endl;
cout << setw(4) << "|" << setw(5) << "|" << endl;
cout << setw(4) << "|" << setw(6) << "/ \\" << endl;
cout <<"___|________" << endl;
}
void Gallows(int count)
{
if (count == 1)
LeftArm();
else if (count == 2)
Head();
else if (count == 3)
RightArm();
else if (count == 4)
Body();
else if (count == 5)
LeftLeg();
else if (count == 6)
Hangman();
}
void secret(string fileword)
{
int i = 0;
int x;
string secret;
secret = fileword;
x = secret.length();
cout<<"The word is ";
while (i < x)
{
secret[i] ='_';
cout<<secret[i]<<" ";
i++;
}
cout<<endl;
}
char Question ()
{
char letter;
cout<<"What letter would you like to guess? ";
cin>>letter;
return letter;
}
void DisplayAWord(string guessword)
{
cout << "The word is "<<guessword<< endl;
}
void revealword(char letter,int position,string fileword, string guessword)
{
int i = 0;
int count = 0;
int x;
string secret;
secret = fileword;
x = secret.length();
while (i < x)
{
secret[i] ='_';
i++;
}
guessword = secret;
if(position==0)
guessword[position]=letter;
else if(position==1)
guessword[position]=letter;
else if(position==2)
guessword[position]=letter;
else if (position==3)
guessword[position]=letter;
else if (position==4)
guessword[position]=letter;
else if (position==5)
guessword[position]=letter;
cout<<guessword[0]<<" "<<guessword[1]<<" "<<guessword[2]<<" "<<guessword[3]<<" "<<guessword[4]<<" "<<guessword[5]<<" "<<endl;
}
The problem, I think is in the revealword function? Please help!!!!