Skip to content

Instantly share code, notes, and snippets.

Created May 5, 2017 10:09
Show Gist options
  • Save anonymous/083dd92b402c7962d1e813eb6f069b53 to your computer and use it in GitHub Desktop.
Save anonymous/083dd92b402c7962d1e813eb6f069b53 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
void PrintIntro();
void PlayGame();
string GetGuess();
bool AskToPlayAgain();
// the entry point for our application
int main()
{
PrintIntro();
PlayGame();
AskToPlayAgain();
return 0; // exit the application
}
 
// introduce the game
void PrintIntro ()
{
constexpr int WORD_LENGTH = 9;
cout << "Welcome to Bulls and Cows, a fun word game.\n";
cout << "Can you guess the " << WORD_LENGTH;
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 << "Your guess was: " << Guess << endl;
cout << endl;
}
}
string GetGuess ()
{
// get a guess from the player
cout << "Please guess the letter: ";
string Guess = "";
getline(cin, Guess);
return Guess;
}
bool AskToPlayAgain()
{
cout << "Do you want to play again? ";
string Response = "";
getline(cin, Response);
cout << "First char: " << Response[0];
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment