Is my way to code main() is right?

int main()
{
	do
	{
		PrintIntro();

		PlayGame();

	} while (AskToPlayAgain() == true);
	
	return 0;
	
}

I’ve wrote main() method this way, everything works well but my question is if I didn’t brake any rule by writing code this way?

1 Like

So far I can see it’s looks okay. In my application I use the int main () so all the time. I don’t see anything that is wrong whit it.

Nope, you don’t even need == true there. Would be like Ben putting bPlayAgain == true instead of just the variable.

You say you don’t need the == true but it don’t matter if you do that or not its what coding standard you like.
I normally us also == true its what you like to do. Its the same whit every time you want to get a int 1 up you can do that by i++ or i += 1 or even by i = i + 1 its what you like and you want to use.

Not really the same imo, checking a boolean against true is just going to be whatever the boolean already is. Seems extremely redundant.

@Tim_Enthoven @DanM
Ok guys. thank you both for your reply.

I’ve changed my code, it doesn’t check boolean for what is already is? But question still the same. Is the way is right. It is still different that one done by Ben.

int main()
{
	do
	{
		PrintIntro();
		PlayGame();

	} while (AskToPlayAgain());
	
	return 0;
	
}

I had a similar answer to start with

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

I’m trying to figure out why this doesn’t work, you would’ve thought that it would be okay, checking whether the comparison from AsktoPlayAgain is true and then repeating the rest of the code.

You have errors in your code, it should look like

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

We aren’t passing anuthing to AskToPlayAgain.

1 Like

Privacy & Terms