First it initializes a couple of variables with numeric values, in particular it
sets the starting or current difficulty and the maximum difficulty.
While the current difficulty is less than or equal to the maximum difficulty
It calls the PlayGameAtDifficulty function and passes in the difficulty
variable in as an “argument” not sure if that’s what it’s called in c++ or if that’s exactly what’s happing but it does look similar to what I’ve seen in other programming languages.
Then based on the comments “clears the failbit” and “discards the buffer”.
I have no idea what a failbit is or why you would want to clear it.
The buffer might have something to do with memory as for why it’s being discarded not sure yet.
As for the code that handles doing those two things std::cin.ignore(); and std::cin.clear();
.clear(); and .ignore(); look like methods calls to me.
std might stand for standard output, cin I don’t know and :: syntax is very foreign to.
two lines of code are the most unfamiliar to me as of now.
At the end of each iteration in the while loop the difficulty get incremented by 1.
Once difficulty is equal to max difficulty the while loop stops running and the next lines of code
are executed.
A message is sent to the terminal and the function will return 0 signaling that the function ran with no errors.