Section 2 Lecture 21 - Here's what I used

My method was slightly different from the instructors, but it worked perfectly for me and is a little shorter:

int main()
{
do
{
PrintIntro();
PlayGame();
} while (AskToPlayAgain());

return 0;

}

1 Like

I think coding this way would be more simple and convenient as well.:yum:
Is there any reason why we have to create another bool variable(bPlayAgain) to deal with play again or not?:confused:

===

I just found that Bryant gave a clear point of my question at another similar post :joy:

1 Like

int main()
{
do
{
system(“cls”);
PrintIntro();
PlayGame();
}
while (AskToPlayAgain());

return 0; //Exit the Application
}

I ended up doing the same thing, While it is faster, I assume that once things get more complicated (say, a video game) with lots of variables and bools, it might be a little more clear to use bThis or bThat or bTheOther to check things… It’s good to know both ways probably. I learned a little bit of C++ years ago, so while most of the course so far has been a refresher, I enjoy that he shows so many ways to do things and usually why you shouldn’t do things.

Also, I don’t know if he adds it later, but using the “cls” to clear the console every new game can be really useful to keep things clean, I had to Google it, but I remember using it long ago. Try for yourself if you haven’t!

I used the same approach, it looks cleaner and for this little program so far, it works:

//entry point for the game
void main()
{
    do {                
        PrintIntro();
        PlayGame();            
    } while (AskToPlayAgain());
    return;
}

I guess it will be necessary to create a separate boolean when it will be used by several different functions, like booleans in character controllers which indicate if player is jumping, falling, running, etc.