So, what do YOU think main() does?

Hi! Joseph here, just starting Ben’s Unreal C++ developer course. I believe the (main) function designates the start of our new code. Before main, if I remember from the tutorial, is the code others used to get to where we start our main function. After (main) is whatever we write inside of the main function, but indented. This, if I’m correct, reminds me of “nested if” functions in spreadsheet apps like Excel (Microsoft), Sheets (Google), and Numbers (MacOS). Lemme know if I’m completely off base (or I’ll find out in the tutorial later, haha!)!

I’'l try to explain myself to tbest I can.

So, first two lines of the main function are variable assignments or variable statements of int type.
Then starts with a while loop to check in every iteration the maximum difficulty.

The unknow -for now- function starts with one parameter, the logic implemented in that function has something to do with the difficulty in a way I don’t know yet.

Then, that is the object that prints something in console with two functions. This is my guess… ¿Is treated as data buffer so you have to clear the cache every iteration? I think this is maybe in terms of performance I don’t know if this is true or not

Then is ncreasing the difficulty, and end the loop but keeps running another until the boolean is false. Then you return a message and a code message error of 0. That a presume that’s the alpha and the omega of all main functions in C++.

after the terminal has been clear, the initial difficulty and the endgame difficulty will be set. Then, we run our game until the endgame difficulty is beaten, incrementing our difficulty each time regardless whether the level is beaten or failed

Hi, I’m Jordan and just joined the course. I’d say main() would be a container that holds the main functioning code before it branches off into other containers.

The main() function is the most important part of the code because only there we put all statements to manipulate data, information, math equations, etc. Before that is only libraries, variables, other function needed to run on main () function.
Regards,
Ana Reis

main() is a function that is used by the compiler to look for code to execute something.

I think that the main() function executes a set of instructions that is within the brackets. It can be its own function, or a part of multiple functions within another main(),

Hello, to my understanding the main function is what the computer think the program is. He starts and end with main and executes everything that is inside the main function - nothing more.

The code seems to be running a loop of code that works with the game.
The beggining as is said in green clears the terminal so that it resets itself for the rest of the loop.

The difficulty is then set and the info in fellow is just setting the parameters of the difficulty.

After the game is played, the code must clear and reset from success and failures

I’m not very sure about

but I will assume that is to make the code move forward by “discarding the buffer”.

This adds difficulty if the game was succesfully played:

This just ends the loop and the game once highest difficulty was reached.

This just resets the game entirely.

Not sure yet. the main connect to any of other but to that file.

Here we go! I have some experience with python from a university level course, but very minimal overall experience.

Main sets the difficulty scaler between a minimum and maximum threshold, in this case 2-10.
The game will commence as long as the current difficulty <= maximum difficulty, the game will progress.

Main also clears the value that has been entered as the guess, and then sequentially progresses the current level up.

From what I can assume from my Python knowledge…
The first line clears the terminal, which I’m honestly not sure what that means… Maybe the answer?
The next two lines determine the minimum and maximum difficulty.
After that, all I can guess is that it determines the difficulty given to the player.
I also presume the end is what happens if you win.

Well, most likely, the main function here performs the task of an increase in complexity cycle from 2 to 10 where the variable is assigned a base value of 2 and then++ increases the value by 1. After 10 = 10 is obtained, the loop exits.

I think main() is what the terminal runs to play the game until you either lose or beat the game.

The C++ main() method is the starting point of the program. Everything in the program “branches” off from this starting point. The compiler looks for this main method and then build the program from this starting point.

Main is the controlling part of the code that will run all the other statements within

The main() function primarily encapsulates the processes of the program and runs them sequentially or conditionally.
You can compare the main() function to the conveyor belt on a production line, guiding the input through operations to produce an output.

According to me main function is the most important function of the code we do. I guess it keeps all the necessary to run the game or any other program done in C++.

i think the main() is the point where the code is actually executed

in c# there is void update and void start functions which are in turn similar to the main()

(according to this code) the difficulty level starts at 2 (which we can change to anything)
and ends at 10(which we can also change to anything) and while the MinDifficulty level is smaller than
MaxDifficulty, it will keep on running the PlayGameAtDifficulty() function which takes an int argument according to the code and then we like do some memory management or clear cache or something and then we increment difficulty (which can be anything) to increase the difficulty x + 1

after the while statement becomes false at a point (and only if) we print that you are a master hacker and return 0 to exit without any error

I think that main() does the following things in this order:

  1. system(“clear”) : Clears any words or characters present in terminal, such as terminal versions, logos (made out of text characters) or system information in order to only show the game text.

  2. int … int … while : This section sets the maximum difficulty the game can have and ensures that the current game difficulty does not exceed the maximum difficulty (<=10).

  3. PlayGameAtDifficulty(difficulty) : This is done within the while, this section clears values regarding the current difficulty in order to increase the difficulty. The ++difficulty adds a number to current difficulty.

  4. std::cout << “WOW … \n” : This prints text on screen when the player wins the level. The \n part sets a number according to the level cleared. The return 0 is to close the game without printing error logs on screen.

Privacy & Terms