It executes all of the other function that are called.
I guess the main() function does something like declaring some substances and contains overall functions. And what we write above main() function is specific functions that deal with individual substances that we declared in main()
basically, the main () function acts as a controller
it helps us to use our story ( the play game with difficulty method that we’ve written ourselves that it is at the top).
the main function starts and ends the main part of the program
I think main() is a function, and it is the first function run when our program starts, it is the entry point. Our program ends when the main() function ends. All other parts of our game are run from within main().
I believe the Main() function is as the name implies, the Main block of code holding everything together, and the block of code that gets called at the start of every C++ application. Without its execution, the rest of the code in the program won’t do anything.
I don’t quite understand what the main function does but I do know that when the program initially tries to run it looks for the main function first. So in my mind it is all the code that is necessary for the game when it first starts up. I think it probably will have a lot of code pertaining to UI, when we get to that point, and any initial values that the program needs. Other than that I am mostly clueless and ready to learn more!
I believe the main function is the starting point for a program
I believe the main function sets the integer range (in this case, two ints) that will max at ten due to the while option.
It will then run the code in the other function at the difficulty set between 2 and 10 - which, I assume, has the questions set or randomly generated, then when you complete the question it increases the difficulty, then prints WOW once you complete lvl 10.
I’ve no idea.
I think the main function is kind of like the brain of the computer, it is open and ready to receive information by the programmer. I also think that the entirety of any code written in C++ would either be inside the main function or reference any data from the main function from another function. Basically, if you don’t have a main function, your code won’t even run.
Probably, it’s the place where you can make everything else before int main() run or do a task
I think the main function is the function the computer calls to do the action
main()
It is a body of code to tell the computer to look inside to execute the line of codes until it meets return.
It can take argument input from the command line if needed.
The thing I am unsure is sometimes it compiles without return command. Also, sometimes I need to put return with zero(0) not sure why it’s like that.
Also, sometimes I noticed folks define the main function with a void data type, but many of times I noticed integer data type for main function.
Even I have noticed input argument is voided like the following:
int main(void)
Hi
Starting at line 1 (which is more me the int difficulty = 2;)
line 1: gives the standard starting difficulty to the game by assigning a value to an integer.
line 2: gives the “end of game”/ levels . Also assigns a value to an integer
line 3: starts a while statement with the conditions of running everything in it until you reach max difficulty.
line 4: starts what is going to happen in the while loop.
line 5: calls the user function written above the main
line 6 and 7: explains itself in the comment
line 8: increments difficulty so the difficulty gets higher and the loop will find it’s end once it reaches maxDifficulty
line 9: finishes/ ends the code the loop is supposed to run
line 10: prints the message in “” to the console.
line 11 is the last line main will execute as it’s the value it gives back.
line 12: shows end of main’s code.
Well this is my over view of the code.
Main function is function that is compiled 1st in the whole written program, if we make self declared function or class then we have to use it into the main function to call and execute them.
thank you.
i don’t quite know what main() means. but i think that it means this is what we are running, we are not running anything else.
In the main function the while
cycle is running until one overcommes the maxDifficulty
at each stage the function PlayGameAtDifficulty()
is called and after that the input terminal is cleared and the difficulty raised by one.
Going off memory, but the main() function is an important part to a program’s operation. It tells the computer what are the important parts of the program and what values it should return when the program has finished executing. It’s important for a main() function to always return a value, otherwise the function will not work correctly,
If we are to look at this code’s main() function, it begins by clearing the terminal, then setting integer values for difficulty and maxDifficulty. int difficulty begins at 2 and int maxDifficulty is set to 10. The main() function checks to see if difficulty is less than or equal to maxDifficulty, and while that statement is true, it will call the function PlayGameAtDifficulty(difficulty), which allows us to play the game. The difficulty will also increase by one each time while the condition of (difficulty <= maxDifficulty) is true, and if not, it will print “WOW - You’re a master hacker!\n” and return 0; exiting the function.
So I think the main() function is that will in fact execute your program. It will also load all declared libraries and functions before main() was called.