I’m going through the Sorting Hat project, and I’m a bit confused on something. If the max variable is just being used as a placeholder for a value of zero, and letting us say gryffindor is greater than 0, I’ve discovered that max can be called anything. I even changed it from max to “steve” and it still worked. It’s soley to give it a placeholder for 0 from my understanding. What I’m lost on is why we need to say max = gryffindor; in the if statement curly braces. If the house name is greater than zero, the IF’s curly braces still tell the house string variable to correspond with it. As you can see in the picture I left all those out and it’s still running as expected. Is this just good practice to include this sort of thing in case you would need to call the max function later? Am I missing something??
It’s not the string house that is greater than max, it’s one of the integers (gryffindor, hufflepuff, slytherin or ravenclaw) that you declared at the beginning, where you add the points to. the string is used after you know which house has won, you can give that string the name of the house that won and then use that to output the house name, without having to make different cases for the different winner.
ie. ravenclaw has the most points, you give the string house the name ravenclaw, then you can say std::cout << house << “won!” as an output.