Hello everyone, I'm making a game of hangman. I got the original code from err0r1212, and wanted to build upon it and change some things. However, I'm not familiar with the bool function. I'd like to remove the "play again" function, but if I delete it errors come up of course. I'm really new to c++, but I know the basics. If someone could help me remove the play again function, I'd really appreciate it :)
if (match(guess, THE_WORD))
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
cout << "That's right! " << guess << " is in the word.\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
for (int i = 0; i < THE_WORD.length(); ++i)
if (THE_WORD[i] == guess)
soFar[i] = guess;
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout << "Nope, " << guess << " isn't in the word.\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
++wrong;
}return guess;
}
bool playAgain() // function to play again while clearing system
{
char again;
cout << "\n\nWould you like to play again? <y/n>: ";
cin >> again;
It's not clear if you want the game to continue indefinitely, or to only play once.
The simplest solution is to change playAgain() to return a fixed value.
1 2 3
bool playAgain() // function to play again while clearing system
{ returnfalse; // Assumes you don't want the game to play indefinitely
}
If you want the game to play indefinitely, then return true.
If you want to get rid of the function altogether, then you will have to get rid of the do/while loop that calls playAgain().
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.