I have one more question about this hangman situation. How do i get the guessing loop to break after i have guessed all 5 letters in the puzzle? I tried 2 ways to try to get the loop to break after all the letters have been guess. I have // out the code that i tried to attempt using. I used bool in which if all the letters were true, that the if statement would break; I think the If statement in which states if they are all true only works if one is true.
I also used the counter inwhich if 5 letters are guess correctly it would break, however that issue is that i can use the same letter thats already correctly guessed, and have it count as a second time correct. If this method is part correct, how do i disable that if statement (if possible) after its been used once the corrected letter is used.
If anyone possibly knows the solution to my prob, or a better way of exiting this loop after all 5 letters are revieled. Feel free to share your knowledge. - Thanks
CODE
// bool letter1 = false;
// bool letter2 = false;
// bool letter3 = false;
// bool letter4 = false;
// bool letter5 = false;
char guess;
char c1='_',c2='_',c3='_',c4='_',c5='_';
int counter = 1;
// int rGuess = 0; //correct letters guessed
while ( counter <= 10) //loop continuation up to 10 times
{
cout << "\nPuzzle: "<< c1 << " " << c2 << " " << c3 << " " << c4 << " " << c5 << " ";
cout <<"\n" << counter << " Enter a letter guess: ";
counter++; //increment control variable by 1
cin >> guess; // put user input into 'guess'
system("cls"); // Clear screen
if (guess == pAnswer[0] )
{
c1 = pAnswer[0];
// rGuess++;
// letter1 = true;
counter--;
cout << "\nGreat Guess \n\n";
}
if (guess == pAnswer[1] )
{
c2 = pAnswer[1];
// rGuess++;
// letter2 = true;
counter--;
cout << "\nGreat Guess \n\n";
}
if (guess == pAnswer[2] )
{
c3 = pAnswer[2];
// rGuess++;
// letter3 = true;
counter--;
cout << "\nGreat Guess \n\n";
}
if (guess == pAnswer[3] )
{
c4 = pAnswer[3];
// rGuess++;
// letter4 = true;
counter--;
cout << "\nGreat Guess \n\n";
}
if (guess == pAnswer[4] )
{
c5 = pAnswer[4];
// rGuess++;
// letter5 = true;
counter--;
cout << "\nGreat Guess \n\n";
}
// if ( letter1 == true, letter2 == true, letter3 == true, letter4 == true
// {
// cout << "The word is "<<pAnswer.c_str()<<" GREAT JOB!!!\n\n";
// break;
// if ( rGuess == 5 )
// {
// cout << "The word is "<<pAnswer.c_str()<<" GREAT JOB!!!\n\n";
// break;
// }
else
{
cout << "\nThis word doesn't contain the letter\n"<< endl;
}