The problem is precision. TI-83 type calculators store only 14 digits of real numbers, so when you divide a number by 1029, take the fractional part, and multiply by 1029 again, you lose some precision in the process.

I'll run you through your example:

On the first step, A = 1071, B = 1029, you find the remainder C = 42. Look closely, though, and you'll find that you actually have C = 41.999999999987. (You can verify this by storing `{C}→L`_{1}, and then looking at `L`_{1} in the List Editor in the Stat menu. Or you can just subtract 42.)

Moving on, for step two, we have A = 1029, B = 41.999999999987, and the remainder C = 21.000000000329. So you can see, at step three you DON'T actually have 42 and 21; rather, you have numbers that are sort of close to 42 and 21. I'm sure you can see why step three fails now.

The solution: think of a better way to get the remainder. Change the order of some of the operations you're doing. Something like this:

`A/B→D`

iPart(D)→E

EB→E

A-E→C

This doesn't have the same precision issues, because your final result is an integer minus an integer times and integer. And here's a better way to write this in one line, without the extra variables:

`A-B iPart(A/B→C`

Another issue of note: the way you're using the If:Then:Else conditional with the Goto is problematic. In general, you should never Goto out of a code block that needs an `:End`, because the calculator will still be waiting for that `:End`, and use up memory to remind itself how many `:End`s it needs to wait for. Actually, in general, you should never even use Goto at all, and instead rely on more orderly control structures like While, Repeat, and For. Here's one way to write your program with a While loop:

`:Prompt A,B`

:While B

:A-Bint(A/B→C

:B→A

:C→B

:End

:A

You can even optimize this program even more by using lists, and Ans, but I'm not gonna get into that here.