So, what do YOU think main() does?

The main() is where you set the game up and describe the scope of what it should do, leading from begin to end. It is the engine of the game, the gag that you set up.

I will say that I have some programming knowledge since I understand Java decently enough. I have taken one college course in C and a few college courses in Java.

The main method starts by clearing the terminal of any previous output. Creates and sets the difficulty variable to 2 and the maxDifficulty variable to 10. Sets up the while loop to run if the condition is met when difficulty is less than or equal to maxDifficulty. Inside the while loop, the main method will run the PlayGameAtDifficulty method with the parameter of difficulty.

At this point, I don’t exactly know the what the std::cin.clear() and std::cin.ignore() methods do. I believe std::cin.clear() clears any input in the terminal. Whereas, std::cin.ignore() ignores any input added into the terminal after being cleared.

After std::cin.ignore() method, then the difficulty will increment by 1. Once the difficulty is greater than maxDifficulty, then the while loop will end and no longer run. A message is output to the terminal of “WOW - You’re a master hacker!” and a new line will be inserted. Exit the main method once you hit return 0.

2 Likes

The main() is a blend of command lines put into one in order to avoid repeating a sequence of code each time you want to execute it muliple times? Does that make sense?

main() Is the primary loop (also a function) of the program. It is saying that while the difficulty isn’t the max, play the game at the new difficulty. At the end, it returns the logic back to the calling program.

I think “main()” is main block of code that allows for the game to progress with difficulty after each successful completion of the previous difficulty.

I have no idea what the Main function means. But i will guess that the Main function is a function where all the other functions revolve around or have some kind of involvement in.

The ‘main’ block of code, to me, reminds me a lot of the ‘render’ function in JS. It acts as the primary block of code that is run in our program. Declared within it are all our variables/functions that in this case are declared above the main function. In JS I think this format is just standard and not enforced but as JS code is executed differently to C++, I am not sure if this holds for C++. Assuming C++ code is run top to bottom, line by line then I imagine everything in the main function must be declared before it the code is compiled.

Hey! Absolute noob here, just wingin’ it, really can only guess what “std::” does, but based on what little seems to be clear to me, main() is just referring to the PlayGameAtDifficulty function to execute, adding one to the difficulty level each time until it reaches maximum, at which point the win condition is met and the game ends.

I’m a complete and total novice but I would assume that main() is the first thing the code identifies. When referred to, the main() would be read first and all supplemental information would be read to see if it matches or correlates with the aforementioned.

int assign variable that is all i can explain

Main() is the function that helps to compile other functions and code. It is needed for code to run. I think

The main function is the function in a program where code gets executed first and if it is not included then the code wont execute.

I think the main() function is where all the code is executed. It also has the main game loop. In this case, we are starting our main difficulty to be 2 and then capping it to 10. So the while loop will run 8 times, incrementing difficulty each time. At the end, we present the user with a message congratulating them.

Hey there. I didn’t want to spam the forum by starting a new topic so I’m just going to reply to yours.

“What do you think main () does?”

Me: I have no freaking clue. I am a -100 beginner :smiley:

Start and Awake are being used while references can be set underneath it

Main looks to me like it is doing the following:

Take into account two integer variables (one called “difficulty” the other “maxDifficulty”
While the variable difficulty is less than or equal to maxDifficulty, we run game. (So until the difficulty is equal to 10, the game will continue)
We then run the game which takes into account what our starting value for difficulty is as a parameter.
“clear()” and “ignor()” sections I’m less certain about, but they seem to be attached to user inputs somehow?
Then we add 1 to the difficulty variable and repeat the while loop that is set to play the game until difficulty is equal to 10.
Once difficulty is equal to 10, we output the string “WOW - You’re a master hacker!”
Last thing we do is return a value of 0, which from the comment leads me to believe that we exit the game.

I sorta learned this in python, but I don’t think it applies in C++:

Main () is like a scanner, it checks if the code, used as a gateway to execute a program independently, meaning no matter where it is placed, it will be executed first.

This is probably wrong, but lets give it a shot!

1 Like

Not quite sure what main() does but I figure it’s the starting point or meant to capture the core functionality of the code.

1 Like

I don’t know anything about C++ and my answer will pretty much show this. I am going to guess that this sets the main settings of the game, like a main menu perhaps.

1 Like

I don’t know much about C++, but I think main() is thing in which one can perform everything, Like it put limit, one cant go out it. that what I under for now.

Privacy & Terms