Can someone explain to me what this does

can someone explain to me what this does max = max + 1;

It increments the max variable by 1.

it means that you take the value of max add 1 to it, then store the result in max.

You will also encounter this syntax that give the same result.

max++;
max += 1; // you can substitute the 1 for any number

Ok thank you

so why don’t we do int max = 1001; ? wouldn’t that be doing the same thing ?

nvm just tried that myself thanks for your help

It depends on the context. I don’t really remember the context in number wizard though.

But normally the max = max + 1;. is used in the context of a loop when you need to count things.

int max = 1001; // is a declaration of variable max, initialized with the number 1001, by itself it wont change.

I would need some context of what are you trying to achieve, or don’t undestand.

Ok, you’re welcome!

yea i figured out the reason why you cant just do int max = 1001; is becuase then it would display on the console max number is 1001 i mean u could still do it and make print not use max but the max = max+1 way is easier

in fact, we should change the min, the reason of showing 999 is min {(1000+999)/2=999.5} that can be solved by min=guess+1 in update function

Privacy & Terms