Better Fix to max not reaching 1000

When reassigning max and min the author’s code uses min =guess; and max = guess;
This is logically incorrect. If guess were the correct number, the user would have pressed enter not Up Arrow or Down Arrow. The correct assignment if the user selects Up Arrow is min = guess +1;
In a similar manner, if the user presses the Down Arrow then max = guess - 1;

Not only does the above correct the logic error, it also makes the code work without the very ugly kluge of max=max +1 at the top of the code.

4 Likes

Great job fixing the logic! I am proud of you!

Wow! Thanks.

The problem with that is you can get a guess of 0 because of “max (which could be 1) - 1”
It’s best to include “min +1” but leave “max” as is. At least, that’s worked out for me so far. Thanks for the suggestion!

1 Like

Privacy & Terms