My working code for lecture 25

Different from Ben’s again but still works!

// entry point of program
int main()
{
PrintIntro();

do
{
PlayGame();
}
while (AskToPlayAgain() == 1);

return 0;
}

while(AskToPlayAgain()); will do the same thing but ditch the numeral strangeness. Yeah, a bool is technically zero or one, but I think if you’re looking for a bool, you want true or false. Most people, if they see == 1 would probably assume that you’re returning an int.

Yeh this is what I’ve done as well. I feel like I wanted a bool to do the proper check and not invoke the method again but it worked. Pasted down here for reference.

// the entry point for our application
int main()
{
	do
	{
	PrintIntro();
	PlayGame();
	//cout << "Response is " << AskToPlayAgain() << endl;
	} 
	while (AskToPlayAgain() == true);
	return 0; // exit the application
}

Fair point, doesn’t make it entirely clear what the code does without taking comments into account.

This is very similar to what i did, it seemed to make more sense and keeps the code simpler. I did make the mistake of putting the play again function twice however, both with in the do section of code and then again for the while.

I did the same thing and same mistake as LDEVO but after compiling I knew it has to be called in while loop once.

Privacy & Terms