Need help with the "Harry potter sorting hat quiz"

I can not understand
int max = 0

Does “max” mean the max among all the numbers?
or
is just a character which equals to 0

And
gryffindor > max
why can “gryffindor” be larger than “max” which is already the largest number?

And
Does “a++” mean a + 1 or a + 1, a + 1 + 1, …
Please help me

1 Like

max is a variable of type int, you can use it to hold on to integers. What it means is up to the programmer.

You can’t know which is largest until you’ve compared them all. Perhaps you might use max to store the largest value you’ve seen so far while you’re still carrying out the comparisons.

a++ increases a by 1 and returns the original value. ++a does the same thing, but returns the new value instead

4 Likes

Hello, I would like to ask a question which was asked in the OP.

we are intializing max at 0, and we are comparing the house int variables to max. What I don’t understand is, why are we comparing each house variable to zero? My (possibly faulty) logic states that we should be comparing house variables to each other, not to max.

Thank you in advance for help.

EDIT: I get it - there are four if statements, each statement checks with the one before to see if it is greater.

1 Like

I haven’t done the project myself. I learned C++ several years ago from another source. From the context of you post, and the code snippet from the OP, I believe the integer variable max is originally assigned a value of 0. Then, as max is compared to each house, if the value of the house is greater than the current value of max, the value of max is replaced by the house value. After checking max against all houses, the value of max will be the highest house value. If you post more code, I may be able to give a better answer, but I believe that this is what is happening.

EDIT: I just noticed your edit. Seems like you got it. :slightly_smiling_face:

Yep!! Thanks for the reply anyway!

1 Like

Hello,

You’ve cleared up a lot, but something is still nagging at my mind: If “max” is declared and initialized to equal 0, obviously every house we compare it to will be more. So wouldn’t the string of “if” statements just stop at the first one?