So, what do YOU think main() does?

FYI, I am not a noob at programming but I’m new to C++.

The main() function first clears up the terminal window, for a fresh screen with just game data, sets default difficulty at 2 (Starting at Level 2), and ramps up difficulty until a maximum of Level 10, at which the game ends and you’re a ‘master hacker’! :slight_smile: For each level of difficulty, the function PlayGameAtDifficulty is called and once the level is played, it goes to the next level anyway…? Game does not end if user ends wrong combination…? In any case, it clears input buffer too before calling the function again.

Is the function that makes the game run, it starts by setting the difficulty to 2, and making the game run while the difficulty is lower than 10. which means that there will be 9 levels.

Is main() basically the code you use to initiate or end all the other processes within the program.

main() it’s the first function that system runs when a c++ application it’s executed.

In this code we see that the application runs as a cmd/terminal application. This is because the ‘std’ I/O library functionality it’s called multiple times in this function. The first line calls it and it clears the terminal, in other words clears all the cmd lines written, in order to let the application starts at the terminal’s first line in case you’d been using it before starts this application.

The main function then declares two ‘int’ variables that stores the value of the difficulty of this game. Difficulty starts at 2 and the max difficulty will be 10.

While difficulty it’s lower than 10 a code block is executed. At the first time this function is executed difficulty it’s 2 so the code inside it’s executed. This code executes a function named PlayGameAtDifficulty that needs the difficulty parameter. This function code isn’t shown at us so we are going to suppose that executes the core of the game at a given difficulty.

When PlayGameAtDifficulty function returns the control to main function there are two std library function executed that cleans the buffer of the user’s cmd/terminal entry (cin). This prevents that the previous usage of ‘cin’ stores stuff that we don’t want at the application buffer. In main we don’t see an usage of this user input so we can suppose that PlayGameAtDifficulty function is using it. This can be just a preventive technique. We can discuss if these ‘cin’ management functions should be executed here or at the end of PlayGameAtDifficulty because IMO a function mustn’t take responsibility of other functionality that it’s called inside. In case that this is a preventive technique then it’s all right.

No matter where the user input management function are executed difficulty increases and while block of code executes again until the difficulty arrives to max and the user wins the game.

At the end a message to the user is sent with the cout functionality explaining that he has win and the game closes with the return command that indicates that everything goes well.

I would guess Main () function is the command under which you have to include a task to run in a game, if that makes sense. This is just a guess as I don’t really know what purpose does Main() serve.
I am quite sure that it is not the correct answer, but like you said I am recording my starting point, so I can look back later and see how much more I improved and know by the time I finish the course.

Note to future self: Well done if you completed the course and can now do all the things taught in the course on your own! :smiley:

@ben main() is the starting point of the code. The operating system executing the code starts from the main function, while the other functions are ordered by how they are called by the main() function or a function that was called by main or so on.

main means the head of the code or something. seriously i have no idea

So i’ve been using c++ for some time now, but never really asked myself the question of what does main do, for me it’s the “main” function, it’s the function that is executed at first, it will involve some commands for closure of the program like cout commands and other function are being called from there!

I have no idea, but i think main gives instructions to the rest of the code on how to behave.