So, what do YOU think main() does?

Well without hardly knowing anything about coding at this point, I’m going to guess main() is some sort of function that will contain or store the main set of code for one of the primary functions of the program, so that it can be called later.

it calls the function PlayGameAtDifficulty and as the user clears the stage it increment the diificulty and then this loop goes till difficulty is 10 after that the game ends by saying WOW - You’re a master hacker!

I believe the main function keeps the user playing the game until the limit in which the coder established of difficulty is reached. Once the limit is reached it would prompt the user they had beat the game.

So okay, here I go with my, very likely embarrassingly, attempt to explain what I think the main() does/means:
Now I have given some coding a go a couple of times and I;m not ENTIRELY new to coding and what I think the main() does in C++ is to set the record straight - in layman’s terms. I think all the variables are set to their initial states, and the “game” or “program” is basically set to starting point. I don’t know how to more explain what I’ve got in my head as of now but this is basically the best way I know how to explain it. Hope this is at least 10% correct lol

I have not go a clue. But I assume main() dictates the conditions of the game whether the player is correct or incorrect

I think that the main function is the setup and that it also controls the game. As you can see at the top of the code, it begins by clearing the terminal and then continues to setup variables that will be needed in the game. It also starts off the game with the while loop that will end once you’ve finished the max difficulty level. What the std::cin.clear() and std::cin.ignore() means, I’ve got no idea. I do know that inside the while loop, a function that contains the logistics of the game will run and then the difficulty will rise if you have completed the level. At the end, it congratulates you on winning the game and then exits.

I have a little backround in PHP so some parts are familiar. It looks like it:

  1. Sets a couple variables with an integer type
  2. Runs a while loop that will go until difficulty reaches maxDifficulty (incrementing +1 each time it loops)
  3. Inside the while loop it runs a separate function called PlayGameAtDifficulty, passing in the difficulty variable. After that it seems to control the output buffer, but I’m not sure what “failbit” means.
  4. After the loop, it outputs the “win” condition text and stops execution by returning 0.

Briefly, the main function is where everything start and End. There must be one main function only which is responsible for fetching the program statement by statement.

Hello, I am new to C++ & am unsure exactly what the main() function does. Within time my response to this question, I will be able to provide a proper answer!

I think it sets a group of syntax that you can retrieve from C++ easily.

Main is the starting point for the game. The compiler starts there and begins to run the program within.

Main starts the program with a difficulty level and contains a maximum difficulty level. If the maximum difficulty level is not reached, you do not win the game and therefore lose/die. If the difficulty is less than maximum and pass the current level (PlayGameAtDifficulty(difficulty)), then the difficulty will be incremented and you will proceed to the next level. When you have finally reached the last level, and win it, it will output the print statement "WOW - You’re a master Hacker!, and then print a new line and return 0.

At the start the terminal is cleared.
Starting at game difficulty level 2 the game will go until difficulty 10.
Then game function is asked with the diffuculty level.
If you have mastered level 10. The message will show up "WOW - You re a master hacker!\n

I believe the curly brackets {} is the method that the ‘while’ function will be doing. So there isn’t a ‘;’ as its not the end of the function. The function on happens at the end of the lines inserted between the {}

main() is a method that will be programmed. the parenthesise with no ‘;’ means that something needs to be written after to make it work.

I am clueless

()main

Is this a description of what is going to happen? A starting point of the objective? In the case of Triple X, would this be to determine the point of the game?

Just beginning the Unreal and C++ course and as per the challenge set by Ben, I’m going to be describing what I think main does before I’ve started programming the TripleX game.

I think that main() is body of the program, the entire process of the program from start to end runs within it.
While other functions may exist outside of it, they are called within the main() section and run according to the order of commands within it.

i think the Main Function is a function used as a primary key to make basic things on the language happen… i can’t put it too well, but its like a core code for C++ idk just new here

I think main() function is where the main body of the program exists…between the indentations.

Privacy & Terms