#include
#include
using namespace std;
//Prototype for the encapsulated abstraction
void PRINTINTRO();
void PLAY_GAME();
string GETGUESS();
bool AskTOPlayAgain();
// This is the entry point of the game
int main()
{
do
{
PRINTINTRO();
PLAY_GAME();
}
while (AskTOPlayAgain()==1);
return 0;
}
void PRINTINTRO()
{
// Introduction for the game
constexpr int WORD_LENGTH = 9;
cout << "Welcome to Bulls and Cow.A fun word game\n";
cout << "Can you guess " << WORD_LENGTH;
cout << " letter isogram I am thinking of?" << endl;
cout << endl;
return ;
}
void PLAY_GAME()
{
// Looping for the no of turns
constexpr int NO_OF_TURNS = 5;
for (int i = 1; i <= NO_OF_TURNS; i++)
{
string GETGUESS();
// Print back the word for player
cout << "Your guess is: " << GETGUESS() << endl;
cout << endl;
}
}
string GETGUESS()
{
// Ask the player to enter a word
string GUESS = "";
cout << "Enter your guess: ";
getline(cin, GUESS);
cout << endl;
return GUESS;
}
bool AskTOPlayAgain()
{
cout << "Do you want to play again?";
string RESPONSE;
getline(cin, RESPONSE);
cout << endl;
cout << endl;
return (RESPONSE[0] == 'y') || (RESPONSE[0] == 'Y');
}
I Wrote the Code for DO while in the following way, and it works. wonder what complications would happen ??