Here is my complete code:
#include <iostream>
#include <string>
using namespace std;
void PrintIntro();
void PlayGame();
string GetGuess();
bool AskToPlayAgain();
// the entry point for our application
int main()
{
do
{
PrintIntro();
PlayGame();
AskToPlayAgain();
} while (AskToPlayAgain());
return 0; // exit the application
}
// introduce the game
void PrintIntro()
{
constexpr int WORLD_LENGTH = 9;
cout << "Welcome to Bulls and Cows, a fun word game.\n";
cout << "Can you guess the " << WORLD_LENGTH;
cout << " letter isogram I'm thinking of?\n";
cout << endl;
return;
}
// loop for the number of turns asking for guesses
void PlayGame()
{
constexpr int NUMBER_OF_TURNS = 5;
for (int count = 1; count <= NUMBER_OF_TURNS; count++)
{
string Guess = GetGuess();
cout << "Your guess was: " << Guess << endl;
cout << endl;
}
}
// get a guess from the player
string GetGuess()
{
cout << "Enter your guess: ";
string Guess = "";
getline(cin, Guess);
return Guess;
}
//Ask the player to play again, yes or no?
bool AskToPlayAgain()
{
cout << "Do you want to play again y/n?";
string Response = "";
getline(cin, Response);
return (Response[0] == 'y') || (Response[0] == 'Y');
}