Return PlayGame()


I noticed that there is no return in the PlayGame() function.
Is there a specific reason for this, because Ben said to always use return in functions?


P.S.: this is the code:

     void PlayGame()
    	// loop for the number of turns asking for guesses
    	constexpr int NUMBER_OF_TURNS = 5;
    	for (int count = 1; count <= NUMBER_OF_TURNS; count++) {
    		string Guess = GetGuess();
    		cout << "Your guess was: " << Guess << endl;
    		cout << endl;

I noticed the same… I have added the ‘return’ just before the last bracket. It works that way, and I am following Bens earlier advice. :slight_smile:

Actually the return statement is where the function exits. If you didnt type in void functions, the compiler assumes that the “exit” is at the end. In void functions is a little redundant to write return because normally you want your function to execute all the lines before it exits.
Try this:
In PrintIntro() type the “return” statement in the first line. Your program will be still calling the function and everything will work normally, but the function will exit before print anything on the screen.

Thanks for the help guys!

Privacy & Terms