Problem with my code? not working

#include
#include

using namespace std;

//Apparently putting this at the top and the body at the bottom lets you have the function’s code after the function it is used in?
void PrintIntro();
void PlayGame();
string GetGuess();
void PrintGuessBack(string Guess);
bool AskToPlayAgain();

//The automatically run function.
int main() {
PrintIntro();
PlayGame();

return 0;

}

//Introduce the game.
void PrintIntro() {
constexpr int WORD_LENGTH = 9;
cout << “Welcome to Bulls and Cows, a word guessing game.\n”;
cout << “Try to guess my " << WORD_LENGTH << " letter isogram.\n”;
return;
}

void PlayGame() {
//GetAndPrintGuess() loop.
constexpr int TRIES = 5;
for (int count = 1; count <= TRIES; count++) {
string Guess = GetGuess();
PrintGuessBack(GetGuess());
}
return;
}

string GetGuess() {
//Get the guess from the player.
string Guess = “”;
cout << "What is your word guess: ";
getline(cin, Guess);
return Guess;
}

void PrintGuessBack(string Guess) {
//Repeat the guess back to the player.
cout << "Your guess is " << Guess << “.\n”;
cout << endl;
return;
}

bool AskToPlayAgain()
{
cout << "Do you want to play again? ";
string Response = ";"
getline (cin, Response);

cout << "Y or N " << (Response[0] == 'y');

return false;

}

shouldn’t this part be:

string Response = “”;

?

The problem with your code is that the function AskToPlayAgain is always returning false
no matter what you type as an answer.

You should write the code like this instead:
return Response[0] == ‘y’;

Privacy & Terms