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!
#include
#include
using namespace std;
void PrintIntro();
void PlayGame();
string GetGuess();
void PrintGuess(string);
//the entry point for the application
int main()
{
PrintIntro();
PlayGame();
return 0;
}
void PlayGame()
{
//loop for number of turns asking for guess
constexpr int NUMBER_OF_TURNS = 5;
for (int i = 0; i < NUMBER_OF_TURNS; i++)
{
GetGuess();
cout << endl;
}
}
//introduce the game
void PrintIntro()
{
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;
return;
}
//get a guess from the player and print it back
string GetGuess()
{
string Guess = “”;
cout << "What word am I thinking? ";
getline(cin, Guess);
PrintGuess(Guess);
return Guess;
}
void PrintGuess(string Guess)
{
cout << "You Guessed: " << Guess << endl;
return;
}