Bug - game asks for Guess three times before each Print. Why?

Hi, I tried going my own way. Like many others I tried having a seperate function for GetGuess and PrintBack.
However, it asks for input twice at first, then 3 times thereafter. I suspect line 59 and 60 both run the GetGuess() function instead of printing its value. Why? How do I fix this? And if this is the case, why does it only ask twice at first instead of 3 times?

Because everytime you are calling the method GetGuess() you are making print it all over again.

First time:
when the loop say:


Second time:
When you use it to get the Guess value on the PrintBack():

cout << "Your Guess was: " << GetGuess() << end1 << end2;

Third time:
When the PrintBack() returns GetGuess():

return GetGuess();

You are using it to get the Guess value, but everytime it will pass through the print method before return the string that you want

If you take the PrintBack() method out of the loop and put it inside the GetGuess(), change it’s return type to void and change the GetGuess() within the cout << "Your Guess was: " << GetGuess() << end1 << end2; to just Guess, it should work (although you would have to initialize the guess outside those methods)

Privacy & Terms