Feedback on a different method

My first post on here, really enjoying the tutorials so far, so thanks for all the hard work put into them.

I have got just a quick question reference to the DO WHILE loops.

I created it in the following way which seems to work just fine:

int main()
{
	PrintIntro();

	do
	{
		PlayGame();
		
	} while (AskToPlayAgain() < 0);
	
	return 0; // Exit the application
}

It even appears to be a little more clean than the one shown in the lecture. I knew the boolean would return a zero or a one, so thought it would be just easier to react on the functions result of that number.

I am sure there is a reason for this, but just wanted to see what it was so i dont make any mistakes like this going forward.

Thanks once again

This is always going to be false. 0 isn’t less than 0, 1 is also not less than 0, ergo both possibilities are false.

I would suggest either using the value directly as described by the annotation in the lecture
while(AskToPlayAgain()) or comparing it to a true/false i.e. while(AskToPlayAgain() == true)

I have used your code to exclude PrintIntro() outside of the do while loop too, because only one introduction is necessary.

I have used DanM’s suggestion.

Privacy & Terms