May have made this a bit more complicated than I needed to

I did the For loop inside the GetGuessAndPrintBack function, and made it a lot more cumbersome than it probably needs to be, by the looks of how Ben did it…

string GetGuessAndPrintBack()
{
// get input of guesses from player
string Guess = “”;
cout << “Enter your guess now:”;
getline(cin, Guess);

  // loop the questions and answers

for (int Count = 1; Count <= Limit; Count++)
{
std::cout << “Take a guess” << endl << endl << "this is try number " << Count << “:”;
getline(cin, Guess);
std::cout << endl << "You guessed: " << Guess << endl;

}
return Guess;

First, remove “std::” from your loop, since you’re already using the nameplace, according to the rest of your code.

Second, don’t bother with the first “endl” in your loop and replace with “\n” in your quote, as so:
cout << “Take a guess\n” << endl << "this is try number " << Count << “:”;
getline(cin, Guess);

Rather than:
std::cout << “Take a guess” << endl << endl << "this is try number " << Count << “:”;
getline(cin, Guess);

Third, you do not need to use “//get input of guesses from player” since your string is called “GetGuessAndPrintBack”, the purpose is rather straight-forward.

Sorry, if I sound preachy, I just thought that these tips would help you keep your code shorter and cleaner.

Hey the whole point of posting here is to great preached advice to! Much appreciated!

1 Like

Privacy & Terms