-
-
Save anonymous/a886cffa66b17ed8c7b9ad9deec219e7 to your computer and use it in GitHub Desktop.
lecture 25 challenge
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() | |
{ | |
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