Sec 2 part 29 - "Play it again Sam" .. or not

Since My last post I have gotten the Y/N prompt to work… for the most part (above image).
If the keystroke is “Y” then the value returns true. If keystroke “N”, it returns false. Any other character will cause the question to be re-asked.

NOTE:My initial test of this function used a simple return 0 with the text displayed according to what was pressed. The std::cout is just a remnant of that

The problem lies in the calling the game to play again.

Second image shows my INT MAIN() function. Going down to line 297 is where the game leads you to the Game complete screen, and somewhere in here is where I believe the problem is. For some reason (and what I am hoping the community can point to) I cannot get the game to start over.

My thought process was / is as follows:

  1. Make a variable to hold the value of the PlayAgain() function. :heavy_check_mark:

  2. Run the GameCompleteOutro() function. :heavy_check_mark:

  3. Run PlayAgain() function. This should carry the value of the bool PlayAgain(bool surveySays) turning it over toPlayAgain(RoundTwo). Which in turns get tucked into the local variable bool RoundTwo. :question: :question: :question:

  4. If statement to check whether RoundTwo is true or false and run the code accordingly. If true the goto gameStart; , located near the top of main() function, kicks off the whole game over. If false the game exits to the command line. :interrobang: This worked before and is still working within the bool PlayAgain() function for the pressing something other than y/n so I really don’t think this is wrong either.

I just don’t see where I am going wrong. Any solutions would be appreciated. I want to get this down before I start randomzing the numbers…

-C

  1. goto is widely discouraged due to easily made spaghetti. It has very limited legitimate reasons to be used. Your case is not one of them, use a loop instead.
  2. The variable you are passing into the function isn’t being used and redundant as it’s just the return value.
  3. You aren’t doing anything with the return value
    Quick example of how you return values.
    int square(int n)
    {
        return n * n;
    }
    int main()
    {
        int value = square(3);
        return 0;
    }
    
    Here 3 is passed into the function, multiplied by itself and returned to the caller. So in this example value holds the value 9.
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms