Hello again,
so here is how I cleaned it up and separated the Guet Guess and Print Guess.
I made another String Method, mainly because both were under a string before that, yet it got me wondering when should I use a void… I had to play around a bit with the actual “string Guess =” statement for the PrintGuess method, it seemed logical to give it the result of the Get Guess, I am not sure if I set the value the right way or if there is another way but it works in the end.
#include <iostream>
#include <string>
using namespace std;
void PrintIntro();
void PlayGame();
string GetGuess();
string PrintBack();
//The entry point of our application
int main()
{
PrintIntro();
PlayGame();
return 0; // exit the application
}
// loop for the number of turns asking for guesses
void PlayGame()
{
constexpr int NUMBER_OF_TURNS = 5;
for (int count = 1; count <= NUMBER_OF_TURNS; count++)
{
GetGuess();
PrintBack;
cout << endl;
}
return;
}
// introduce the game
void PrintIntro()
{
constexpr int WORD_LENGTH = 9;
cout << "Welcome to Bulls and Cows, a fun word game.\n";
cout << "Can you guess the " << WORD_LENGTH << " letter isogram I'm thinking of?\n\n";
return;
}
// get and guess from the player and print it back
string GetGuess()
{
string Guess = ""; //First char Uppercase value for Unreal standards
cout << "Enter your Guess: ";
getline(cin, Guess);
return Guess;
}
// Print Guess
string PrintGuess()
{
string Guess = GetGuess();
cout << "Your guess was: " << Guess;
cout << endl;
return Guess;
}
Cheers!