Created
August 27, 2017 09:38
-
-
Save SuperRockman/ac819c76807a1339cc3fe63ed93be233 to your computer and use it in GitHub Desktop.
This Code
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 int32 = int; | |
struct Info | |
{ | |
const int32 numberOfTries = 5; | |
const int32 isoLength = 5;//variable to store isogram length | |
std::string userGuess = "";//store the guess in string | |
}; | |
std::string getGuess(std::string guess, int32 wordLength) | |
{ | |
while(guess.length() != wordLength) | |
{ | |
std::cout << "enter a valid guess: " << std::flush; | |
std::getline(std::cin, guess);//get a guess from the player | |
} | |
return guess; | |
} | |
//introduce the game | |
void printGame(int32 wordLength) | |
{ | |
std::cout << "Welcome to Bulls & Cows" << std::endl; | |
std::cout << "Can you guess the " << wordLength << " letter isogram?\n" << std::endl; | |
} | |
//prints the guess back to the player | |
void printGuess(std::string guess) | |
{ | |
std::cout << guess << std::endl << std::endl; | |
} | |
void playGame(Info data) | |
{ | |
for (int32 currentTry = 0; currentTry < data.numberOfTries; currentTry++) | |
{ | |
printGuess(getGuess(data.userGuess, data.isoLength)); | |
} | |
} | |
//application entry point | |
int main() | |
{ | |
Info data; | |
printGame(data.isoLength); | |
playGame(data); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment