I couldn’t figure it out on my own. After looking at HavocBlast’s code, it finally made sense. I kept trying to run through Google and cplusplus.com to figure it out and the examples given to my (probably poorly worded questions) were more confusing than helpful. After looking at HavocBlast’s code it started to add up.
- I just needed to prototype PrintGuess with a string parameter.
- I needed to give a parameter name that I would then push through “cout”
- By including the PrintGuess function into my GetGuess function, I just had to add “Guess” and it would print properly.
The only problem I see after writing this out is that it didn’t seem to fully separate the function. I’m still printing the guess from within my GetGuess function. Although, the concept of passing variables is starting to make sense. Thanks HavocBlast!
using namespace std;
//the entry point for the application
//loop for number of turns asking for guess
constexpr int NUMBER_OF_TURNS = 5;
for (int i = 0; i < NUMBER_OF_TURNS; i++)
cout << endl;
//introduce the game
constexpr int WORD_LENGTH = 5;
cout << “Welcome to Bulls and Cows, a fun word game” << endl;
cout << “Can you guess the " << WORD_LENGTH << " letter isogram I’m thinking of?\n”;
cout << endl;
//get a guess from the player and print it back
string Guess = “”;
cout << "What word am I thinking? ";
void PrintGuess(string Guess)
cout << "You Guessed: " << Guess << endl;