Question about GetGuessAndPrintBack()


Quick question for those more experienced with C++

I’m wondering why exactly, at the end of the GetGuessAndPrintBack function, we used
return Guess; and not return GetGuessAndPrint;

Thanks a bunch

At the end of the GetGuessAndPrintBack function we returned Guess because that is the the string variable where the word that is our guess for the game is stored.

1 Like

Thanks, that makes sense to me soon after my post. I think there was some confusion as to why we wouldn’t have returned to GetGuess , the first variable in the function.

My question is similar to this. Why are we returning a string at all? We are printing out the user’s guess with the code…

cout << "You just entered " << Guess << endl;

…but as far as I can tell we aren’t doing anything with the returned Guess in Main(). Am I missing something?

Later the function becomes GetGuess() and the returned value will be used.

I’ll leave this here for future people:

We return the value of the variable Guess at the end of GetGuessAndPrintBack so you can possibly seperate the GetGuess from the PrintBack (as it was when we had it all in the main function). Without that we would not possibly be able to use the variable Guess outside of GetGuessAndPrintBack. If you separate GetGuessAndPrintBack you do need Guess in PrintBack, but it’s only defined in GetGuess, so you get an error that Guess is not defined.

Hope it helps someone :slight_smile:

Privacy & Terms