#include <iostream>
#include <string>
void introGame();
void playGame();
std::string getGuess();
void printBack();
int main()
{
introGame();
playGame();
return 0;
}
void playGame()
{
//Looping through the number of tries
constexpr int maxTries = 5;
for (int input = 1; input <= maxTries; input++)
{
printBack();
std::cout << std::endl;
}
}
// Introduce the Bulls and Cows game
void introGame()
{
constexpr int wordLength = 5;
std::cout << "Welcome to Bulls and Cows, a fun guessing game." << std::endl;
std::cout << "Please guess a " << wordLength;
std::cout << " letter word that I am thinking of.\n";
return;
}
// Get a guess from the player and print it back
std::string getGuess()
{
std::cout << "Please enter your guess..." << std::endl;
std::string sGuess = "";
std::getline(std::cin, sGuess);
return sGuess;
}
void printBack()
{
std::cout << "Your guess was " << getGuess() << std::endl;
return;
}
Not sure what you mean
I apologize ahead of time if my terminology is incorrect. Trying to get in the habit of speaking the new jargon! Hopefully this help clarify in, unfortunately, a more lengthy ‘essay’.
After posting my answer in the code above, and then viewing the solution in the other half of the video, I noticed this video solution to be quite different from my solution - although mine still works for now!
What I did was have playGame() enter a loop, which called printBack() 5 times, and when printBack() was called, printBack() called getGuess(), and when getGuess() was called getGuess returned sGuess and used that value all the way back down the stack into main to execute.
Generally, I am wondering if my solution compared to the video solution is equally effective, more effective, or less effective. And if less effective, I would love to know why so I can use that reason with further coding solutions!
Thanks!
Seems fine to me. Though the fact that printBack is a single std::cout which calls getGuess() makes it seem a tad unnecessary. When you go over parameters you can refine this so the function takes a std::string and uses that in the std::cout line.