My solution

#include
#include

using namespace std;

void PrintIntro();
void PlayGame();
string GetGuess();
string PrintGuess();

string Guess = “”;

int main()
{
PrintIntro();

PlayGame();

return 0;

}

void PrintIntro()
{
// introduce the game
constexpr int WORD_LENGTH = 4;

cout << "Welcome to Bulls and Cows, a fun word game." << endl;
cout << endl;
cout << "Can you guess the " << WORD_LENGTH << " letter isogram I am thinking of? " << endl;
cout << endl;

return;

}

void PlayGame()
{
constexpr int TRIES = 5;
for (int Count = 1; Count <= TRIES; Count++)
{
GetGuess();
PrintGuess();
}

return;

}

string GetGuess()
{
// get a guess from the player
cout << "Enter your guess here: ";
getline(cin, Guess);
cout << endl;

return Guess;

}

string PrintGuess()
{
// print guess to player
cout << "Your guess was: " << Guess << endl;
cout << endl;

return Guess;

}

This is similar to the solution I used. I am trying to figure out why the solution that was used in the lecture is preferred over this one. I like having the Guess defined as a string at the beginning. It avoided the undeclared value errors and is easy to find. Is it a good idea to list all of the strings used this way?

I will play with it to see how it breaks.

Privacy & Terms