Skip to content

Instantly share code, notes, and snippets.

/main.cpp Secret

Created August 24, 2017 20:12
Show Gist options
  • Save anonymous/a886cffa66b17ed8c7b9ad9deec219e7 to your computer and use it in GitHub Desktop.
Save anonymous/a886cffa66b17ed8c7b9ad9deec219e7 to your computer and use it in GitHub Desktop.
lecture 25 challenge
#include <iostream>
#include <string>
using namespace std;
void printIntro();
void PlayGame();
string getGuess();
bool AsktoPlayAgain();
int main()
{
do {
printIntro();
PlayGame();
} while (AsktoPlayAgain()==true);
return 0;
}
//Introduce game
void printIntro()
{
constexpr int WORD_LENGTH = 5;
cout << "Welcome to the Bulls and Cows game. "
<< "A fun and challenging word game.\n"
<< "Guess the "
<< WORD_LENGTH
<< " letter isogram word.\n" << endl;
return;
}
void PlayGame()
{
constexpr int NUMBER_OF_TURNS = 5;
//loops for the amount of turns taking
for (int i = 0; i < NUMBER_OF_TURNS; i++)
{
string Guess = getGuess();
//print guess
cout << "Your guess is: "
<< Guess << "\n" << endl;
}
return;
}
//takes users guesses
string getGuess()
{
string Guess = "";
cout << "What is your guess: ";
getline(cin, Guess);
return Guess;
}
bool AsktoPlayAgain()
{
string response = "";
cout << "\nDo you want to play again? ";
cin >> response;
cout << endl;
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