Here is my code, is there a better way then putting all of main() into AskToPlayAgain() to get it to loop?
// BullsnCows.cpp : Defines the entry point for the console application.
//
#include “stdafx.h”
#include “BullsnCows.h”
int main()
{
PrintIntro();
PlayGame();
AskToPlayAgain();
return 0; //exit the application
}
void PlayGame()
{
//loop for number of turns asking for guesses
constexpr int NUMBER_OF_TURNS = 1;
for (int count = 1; count <= NUMBER_OF_TURNS; count++)
{
string Guess = GetGuess();
cout << "Your guess was: " << Guess << endl;
cout << endl;
}
}
void PrintIntro()
{
// introduction to game
constexpr int WORD_LENGTH = 5;
cout << "Welcome to Bulls and Cows, a fun word game." << endl;
cout << "Can you guess the " << WORD_LENGTH;
cout << " letter isogram I'm thinking of?\n";
cout << endl;
return;
}
bool AskToPlayAgain()
{
cout << "Do you want to play again? " << endl;
string Response = “”;
getline(cin, Response);
if (Response[0] == 'y' || Response[0] == 'Y')
{
PrintIntro();
PlayGame();
AskToPlayAgain();
}
else if (Response[0] == 'n' || Response[0] == 'N')
{
exit; //exit program
}
cout << endl;
return false;
}
string GetGuess()
{
//get a guess from the player
cout << "Enter your guess: ";
string Guess = “”;
getline(cin, Guess);
return Guess;
}
BullsnCows.h
#pragma once
#include
#include
using std::cout;
using std::cin;
using std::endl;
using std::string;
//function prototype
void PrintIntro();
bool AskToPlayAgain();
void PlayGame();
string GetGuess();