Created
September 9, 2017 09:31
-
-
Save storm-ace/5ba0e753718baaf5b4cac18adb27d6c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
void PrintIntro(); | |
void PlayGame(); | |
string GetGuess(); | |
bool AskToPlayAgain(); | |
// The entry point for our application | |
int main() | |
{ | |
bool bPlayAgain = false; | |
do | |
{ | |
PrintIntro(); | |
PlayGame(); | |
bPlayAgain = AskToPlayAgain(); | |
} | |
while (bPlayAgain); | |
return 0; // Exit the application | |
} | |
void PrintIntro() | |
{ | |
// Introduce the game | |
constexpr int WORLD_LENGHT = 9; | |
cout << "Welcome to bulls and cows, a fun word game.\n"; | |
cout << "Can you guess the " << WORLD_LENGHT; | |
cout << " letter isogram I'm thinking of?\n"; | |
cout << endl; | |
return; | |
} | |
void PlayGame() | |
{ | |
// Loop for the number of turns asking for guesses | |
constexpr int NUMBER_OF_TURNS = 5; | |
for (int count = 1; count <= NUMBER_OF_TURNS; count++) | |
{ | |
string Guess = GetGuess(); | |
cout << "You guess was: " << Guess << endl; | |
cout << endl; | |
} | |
} | |
string GetGuess() | |
{ | |
// Get a guess from the player | |
cout << "Enter your guess: "; | |
string Guess = ""; | |
getline(cin, Guess); | |
return Guess; | |
} | |
bool AskToPlayagain() | |
{ | |
cout << "Do you want to play again (y/n)? "; | |
string Response = ""; | |
getline(cin, Response); | |
return (Response[0] == 'y') || (Response[0] == 'Y'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment