Triple X prompt - Explain the main function

Hello,

I’m responding to the prompt about the main() function for the triple X game.

The forum link that was in Udemy pointed me to the tag 1_tx_uc2, but there was very little there, and all the responses to this prompt appear to be here in 2_tx_uc2. I’m not entirely sure how these tags work, so hopefully this is the correct place to post this. The different link may be because I purchased the course a year ago…

I am brand new to C/C++, so some of this syntax is odd, but I have some experience with Java, Python, and SQL.

main() function explained:

  • Initializes variables for difficulty and max difficulty
  • While loop calls the game function providing the current difficulty (until that value exceeds the defined max)
  • After the PlayGameAtDiffiuclty() function, there appears to be some cleanup of values used during the game (I assume are defined in the other block)
  • At the end of the loop, the value for difficulty is iterated up by one.
  • After leaving the loop (completing the highest difficulty), prints a statement of congratulations (not sure why it includes a line break) then closes the game.

Thanks,
Andrew

1 Like

Hi Andrew. Welcome to the course and the community.
You’ve covered the main() functionality as covered here so far. The key here is C++ always executes main() first in a program.

Anyway, good luck with the course and I hope you enjoy it.

Privacy & Terms