Created
July 16, 2017 15:07
-
-
Save anonymous/017222c7217672d4eafbbac2e56e2756 to your computer and use it in GitHub Desktop.
This file contains 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(); | |
int main(int argc, const char * argv[]){ | |
PrintIntro(); | |
PlayGame(); | |
AskToPlayAgain(); | |
bool bPlayAgain = false; | |
do { | |
PrintIntro(); | |
PlayGame(); | |
bPlayAgain = AskToPlayAgain(); | |
} | |
while (bPlayAgain>0); | |
return 0; // exit the application | |
} | |
void PrintIntro() { | |
// introduce the game | |
constexpr int WORD_LENGTH = 5; | |
cout << "Welcome to Bulls and Cows, a fun word game.\n"; | |
cout << "Can you guess the " << WORD_LENGTH << " letter isogram I am thinking of?" << endl; | |
cout << endl; | |
return; | |
} | |
void PlayGame() { | |
constexpr int NUMBER_OF_TURNS = 5; | |
for (int count = 1; count<=NUMBER_OF_TURNS; count++) { | |
string Guess = GetGuess(); | |
// Repeat guess back | |
cout << "Your guess is: " << Guess << endl; | |
cout << endl; | |
} | |
} | |
string GetGuess() { | |
// Take user/player guess | |
string Guess = ""; | |
cout << "Type your guess here: "; | |
getline(cin,Guess); | |
return Guess; | |
} | |
bool AskToPlayAgain() { | |
cout << "Do you want to play again? "; | |
string Response = ""; | |
getline(cin, Response); | |
return (Response[0] == 'y'||'Y'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment