My first and second attempts, Lect 21

Ok, before reading other comments or advancing to the solution.

What I did was to include the “do” and “while” in the “main” function. Like so:

//The entry point of our application
int main()      
{
	do
	{
		PrintIntro();

		PlayGame();

		AskToPlayAgain();
	} 
	while (AskToPlayAgain() == true);
		
	return 0; // exit the application
}

There are no errors, but when I run it, I get asked if I want to play, twice… I do not understand why.

But I played around a bit I tried other approaches and while tinkering I realised my mistake in the first place, I was repeating the “AskToPlayAgain” twice, and so I remove it in the “do” and only left it in the “while” and when I run it it works as desired!.

int main()      
{
	
	do
	{
		PrintIntro();

		PlayGame();
	} 
	while (AskToPlayAgain() == true);
	
		
	return 0; // exit the application
}

Now to watch the solution in the video, I will reply with comment.

Cheers!

Ok watched the video and also read the other posts here.

So in the end it seems there are many ways to do this.

Firs of all though the feedback. This lecture was pretty intuitive I did not break a sweat in coming up with the first and second attempt. It is interesting that while I was tinkering one of my tries was to create a new boolean like “PlayAgain” and equate it to the result, but I did not know how to apply that in the function it was giving conflicts and errors, and it is like that when I realized I could simply do the second try.

Now for the actual solution, it would be nice to know if the way most of us seem to have solved this is actually good or not or if the way the class shows it is better and in anticipation of more complexity down the line.

In conclusion the current obstacle is not the logic of it all, but rather the syntax. I am not familiar with the syntax yet, but the logic was easy to understand even anticipate to a degree and part of the syntax in this lecture because it was well explained from the get go in this lecture.

1 Like