main () (Which is a function)is going to run all the statements within the { } also everything with ; is considered a statement. When compiling the program it will look for errors. if there are no errors the value will return 0. hmm looking at while statement I notice a ; is missing. Is that an error?
The main function is the control center of the code. Everything has to get sent back to main and then returned to 0 to compile. The main function controls what gets presented and how it gets it is presented when compiled.
Reading the code above it looks like we will clear the terminal to leave us a blank slate then we will start with a base difficulty of 2 that has a max of 10. If you haven’t reached 10 the game will locate what difficulty you are on and then clear your answer and ignore the buffer??
After that the difficulty will increment by one.
If you make it past the max difficulty you win the game and exit.
I think main is the main area of code that the computer reads. Anything outside of main is not run unless called on. In this case main is just setting some integers then running the game loop and telling the computer to run the function which holds the game itself.
I think “main” is the centralized apparatus that sets and organizes the rest of the code into a cohesive executable formation that manages how it gets actualized.
I studied a bit the programming language C, in C the function main () is the main function of the program, this function is the one that runs the terminal, the program can not run without the function main ().
I’m learning C++ in this course, while having a strong foundation of the C# language.
I think that main() is the equivalent of Start() in C#, which will run at the start of the application.
1- It clears every text in the terminal in the beginning in case there were some text in the terminal from previous testing
2- The game will progress on levels of difficulty until you clear the max difficulty level
3- Finally the terminal will output the end game message and not run anything else
In the main () function there are two variables at startup, the first variable is to determine the level in which you start, the second variable is used to determine which is the last level. Then there is a cycle while (), this cycle what it does is to repeat the game while the current level is less than or equal to the last level to play, if one is wrong in the code to be introduced then you remain at the same level, if the code is correct then the difficulty increases by one. std:: cin.clear (); This line what it does is to clean the buffer what has been written before to avoid errors, std:: cin.ignore () This line what it does is ignore what is in the buffer to avoid entering previously written information.
I honestly don’t really know what the main() function does but I think it basically runs all the statements between the { and } statements. Other than that i don’t know
not sure at this stage, I think there are 10 levels of difficulty, I think this part is if you are successful in getting the code and it makes a means of going to the next level, there’s a return at the end I think to go to the next level
At pretty a much assuming that I’m ‘educated guessing’ level:
It clears the terminal allowing a clean space for the game to run and user inputs to be made.
Chooses the range of difficulties available for the game, the total number of ‘levels’
Not really any idea what the indented bit does, It looks to me like it is what happens if you fail (maybe even if you win), eg it clears what you typed in as an answer and later on in the code it spits out an in story reply to you as the player
This looks like what happens if you ‘win’ and so the numbers you selected are the correct numbers the code is looking for and so it gives you a “WOW - You’re…” message and then return 0; either finishes the game or maybe starts a new one
As a whole, the function of the main() is to be the function that actually executes the game so you can play it, whereas everything written before it is defining what happens when the game is executed. It also increases the difficulty level once a level has been cleared, determines the win condition, and cleans up the terminal so the text doesn’t clutter the screen.
It starts by declaring the two margins of difficulty possible: you start at a minimun difficulty of 2 and every time you succed it increases that value until it reaches 10.
Then you exit the while loop and you get printed “u’re a master hacker”.
The function PlayGame… require the parameter difficulty and on top of that it shapes the numbers that you are going to guess.
cin clear and ignore wipe out and clean the input window
From what I understand, it is the portion of code that will call and play the previous code that we created above it. In essence it is the engine to the program.