What I think the Main() function does

To begin with, I see two integers stating difficulty and max difficulty. I believe max difficulty is obviously the max difficulty you can reach and difficulty is just the current difficulty. It is interesting that it starts at 2 rather than 1 though. I think the while loop is just running the code in the brackets as long as the difficulty is less than or equal to the max difficulty, meaning it stops after they’ve reached level 10. Inside the loop I see the function PlayGameAtDifficulty() with an input of the difficulty variable. I think this is actually playing the game with the difficulty as the input for the function and then once that level is complete exiting the function and continuing the while loop. Next I see what looks to be some sort of print code with .clear and .ignore added to the end which I imagine either clears the text from the screen entirely or clears an error message that appears due to the code. Next I see ++difficulty which is just an easier way of saying to add 1 to the difficulty integer stated above. After it runs that code, it loops until level 10 is completed, then the while loop is broken and the console prints the congratulations text and then 0 is returned so it can exit with no error code according to the comment.

Hopefully this is pretty close to what it actually does. I’m pretty confident I have a good understanding of it due to my previous experience in various programming language, especially C#, but I guess we’ll see as I continue this chapter!

Privacy & Terms