I created a function to print back the guess entered bu the player and called it PrintBack() , after i click Ctrl + F5 the code compiles successfully with no errors, but it asks me to enter my guess twice before printing the result. So all in all i have to enter 10 guesses instead of five as cleared by the screenshot.
.
This is my code:
#include
#include
using namespace std;
void PrintIntro();
void PlayGame();
string GetGuess();
string PrintBack();
// entry point for application
int main()
{
PrintIntro();
PlayGame();
return 0; // exit the application
}
// loop for the number of turns asking for guesses
void PlayGame()
{
constexpr int MAX_NUMBER_OF_TURNS = 5;
for (int Count = 1; Count <= MAX_NUMBER_OF_TURNS; Count++)
{
GetGuess();
PrintBack();
}
}
// introducing the game
void PrintIntro()
{
constexpr int WORD_LENGTH = 6;
cout << “Welcome to Bulls and Cows! A fun word guessing game.\n”;
cout << “Can you guess the " << WORD_LENGTH << " letter isogram i’m thinking of?\n”;
cout << endl;
return;
}
// getting input from the player and then returning it back to them
string GetGuess()
{
string Guess = “”;
cout << "Enter your guess: ";
getline(cin, Guess);
return Guess;
}
// print back what the player has entered
string PrintBack()
{
string Guess = GetGuess();
cout << "You entered: " << Guess << endl;
cout << endl;
return Guess;
}
Thank you.