I'm working on a basic binary number search algorithm. I'm learning computer science, and figured the TI-84 should be able to do this type of algorithm.

You might want to skim the code before continuing, so you understand what I'm saying.

The code runs fine if I say the number ("N") is correct, (press 1, and it displays "Woo hoo!"), or when I tell it the number is lower, (it sets the returned number as the upper limit, and re-runs the equation). But when I try to tell it my desired number is *higher,* it all falls apart, and just returns the same number again. Example:

I set "H" to 100, "L" to 0, and let it run. Calculator returns N, which is 50. When I tell it to go higher, (input "2"), the calculator returns 50 again. The only way I can explain that, is that it's putting "50" in both "H" and "L", which makes no sense. How do I tell it to keep one number the same, and only reset the one I'm telling it to?

Here's the code:

ClrHome

Disp "LOW LIMIT"

Prompt L

Disp "HIGH LIMIT"

Prompt H

Lbl 1

(H+L)/2→N

Disp "CORRECT?",N

Disp "1 IF YES"

Disp "0 IF LOWER"

Disp "2 IF HIGHER"

Prompt A

If A=1

Goto 2

If A=0

N→H

Goto 1

If A=2

N→L

Goto 1

Lbl 2

Disp "WOO HOO!"

Pause

ClrHome

Also, if you know how I could get the calculator to round "N" to the nearest integer, I would appreciate that. Something with the "round(" function, right?

P.S. Please do not tell me to go download an program, or copy someone else's. I'm not doing this to actually utilize program, I'm doing this to learn how these things work.