My thoughts on the main() function

First time ever looking at anything C++ and the last thing I ever did programming-wise was a couple years of Java at college 10 years ago. Still, there are enough similarities to make educated guesses:

The first two lines define variables which are both integers - it sets the “difficulty” integer at 2 and the “maxDifficulty” integer at 10.

The “while” statement repeats over and over until the difficulty integer equals the maxDifficulty integer. It plays the game at a certain difficulty and then increments the difficulty by 1 each time. I don’t know exactly what the comments mean when they say “clears the failbit” or “discards the buffer” but my guess is it has something to do with binary bits and the math happening while you play the game.

I’m guessing the “std::cout” line is similar to the print line function in Java, where it displays that following message to the user playing the game.

I don’t know for sure what the “return 0” line does - maybe it’s just the line that terminates the function?

1 Like

Not bad after 10 years and a different language :wink:

The basics like most languages are basically the same. But Java and c++ do go wildly into different directions. There’s actually quite a lot that’s different between them beyond programming basics.

Thanks! It was fun to see the gaps in my knowledge as I finished the TripleX part of the course. Even though the syntax is different from Java, most of the concepts and flow of writing the code were very similar to what I’m already familiar with. Very excited to see how C++ goes in a wildly different direction once the more complex stuff starts happening :slight_smile:

Privacy & Terms