What I think main() does - BloomingGameDeveloper

The main() function serves as a start to the program. In here you make calls to objects/functions you’ve created to iterate through code in the object/function to either be passed into another object/function elsewhere.

For example in hello.cpp,

We set up two integers, difficulty and maxDifficulty.
Afterward, we create a while loop and while difficulty is less than or equal to maxDifficulty, we then call on PlayGameAtDifficulty(difficulty), and then our set integer, difficulty which equals 2, is passed into the object.

Inside of PlayGameAtDifficulty(int difficulty)

We create a placeholder for the passed integer in between the parentheses. (Parameter)
Two strings are displayed, then the integer previously passed, 2, is multiplied by the modular symbol and then added to itself. Then, the three random numbers generated are added for the int sum variable and multiplied for the int product variable. A few more strings are displayed and product/sum are added in. More integers are set up to receive the answer. A while loop is created to receive the cin, command in, or answer of the user which is then passed into trialSum and trialProduct then the two variables are tested in an if statement which either results in congratulations or a fail.

If the user successfully answers the problem, difficulty is incremented by one until either the game is ended/closed, or until difficulty is greater than or equal to maxDifficulty, 10.

Privacy & Terms