What the main() function is doing (In my understanding)

I have SOME C++ experience in the past since my uncle took it in college so my understanding is on/off in some areas and he let me borrow his old textbooks in the past when I wanted to learn a few years ago before.

main() is a function found in EVERY C++ namespace. Its the one and only. Its kind of like where every function reports back to after it calls for it to be used.

The first two lines make integers (Basically just whole numbers) set to certain values at 2 and 10

The while loop is saying that if the integer difficulty is less than or equal to maxDifficulty (10) to run the loop until the loop fails.

The while loop is calling to the PlayGameAtDifficulty function and plugs in the difficulty integer to tell the game that the game should be played at difficulty level 2 on the first run of the loop.

I’m not quite sure what cin.clear and cin.ignore is doing. My only guess its clearing and ignoring any past input the player gave to the program? cout is outputting and cin is usually user input.

++difficulty is just adding one into the difficulty variable so its value will go from 2 to 3.

The loops going to keep on going until difficulty reaches a value of 11 which the loop will then terminate.

the std::cout is just outputting a string of text and the \n means its making a new line to output it.

return 0; is because int main() has a return type of integers meaning when it ends the function it has to return an integer. Were returning 0 simply to appease the C++ gods and not cause the compiler to throw an error.

Privacy & Terms