TI-86 Basic


Pythagorean Theorem: A2+B2 = C2


What you'll learn:
First of all, Prompt. Here's the syntax:
Prompt variable
Whatever you put as variable will appear on the screen with a question mark after it, waiting for you to type something and press [ENTER]. Input works the same way, but has optional text, like this:
Input "Text:",variable
With both Prompt and Input you can type in numbers. Also, if the graph screen is showing during a program and you just have Input, you can move the pointer around to get coordinates when you press ENTER (good for graphical games). With InpSt you can type in words to save as strings. Then you have getKy, that small, very useful, part of every good game. It checks if a key has been pressed (that's all it does). Before using it you must learn all the other commands on this page. Now you have Lbl, which is just a marker or a placeholder. You shouldn't ever have Lbl without Goto. If you're confused, an example is about to be shown. Goto simply goes to a Lbl.


Code
Lbl A
Input "Age:",A
InpSt "Name:",B
Disp A,B
Goto A


The only way to get out of this program is to press [ON], so it's not very helpful. Keep waiting for the Big One. What if you want something to happen depending on a certain value of A? That's where Conditional Statements come in. Look at the code to see how the If...Then...End helps.

Code
Lbl A
Input "#:",A
Disp A2
If A==0 or A==1
Then
Disp "A = Aany power.
Goto B
End
Goto A
Lbl B
DelVar(A


Notice that even if a command was explained in a previous lesson, I still explain it here, because maybe I used a new form or argument. The TI-85 and TI-86 are the only ones that often need 2 = signs. The code you just looked over (and should understand) is a stand-alone program ...I wouldn't be surprised if something very similar exists on ticalc.org. Make sure you understand everything covered so far before moving on. Next is the If...Then...Else...End statement which does something no matter what, but you have complete control over exactly what happens either way. Look at this example:

Code
Lbl A
getKy→A
If A==22:Goto B
If A==45
Then
ClLCD
Disp 45
Else
Disp A
End
Goto A
Lbl B
DelVar(A


Don't forget about the special cases with If A=22:Goto B and If getKy>0:getKy→A since that saves lots of bytes. This, too, is a stand-alone program, and can be used to find the getKy value for any key, except [ON]. We finally covered the amazing getKy command. You can look at the Key Map Picture. It didn't have to be stored as A, but if we didn't do that only zeros would be displayed, since it's a very fast acting command. A 0 means no key was pressed during that loop. The Else wasn't needed but you need to know how is used. What's left in this lesson?... The While...End & For...End loop, the weird IS>( and DS<(, then the Pythagorean Theorem program to sum up and effectively use what you just learned. I just thought of a good example covering the last 4 commands, here it is:

Code
While getKy=0
For(X,0,100,5
IS>(X,50:Disp "Greater than 50.
DS>(X,50:Disp "Less than 50.
End
End
DelVar(X


The While...End and For...End don't check anything, they only loop. The For...End increases a value by 1 unless a 3rd argument is present (the step, in the it's 5). If you want the routine to run backwards use a negative step; you can't use 0. The While...End loop runs until a certain condition is met. If you notice the adding and subtracting of the DS>( and IS>( cancel each other out, which keeps the For...End running smoothly. They're very rarely used, so don't worry too much about them. For keycodes for any of your programs use the example given. Now for your last command this lesson, Repeat. Simply look at this example, it shows how Repeat can be used:

Code
0→x
Repeat A
x+1→x
Disp x
getKy→A
End
Disp A
DelVar(x
DelVar(A


It's an uncommon command, but useful in keycode dependant programs. An the example it repeats until A>0. Here's what you've probably been waiting for, the Pythagorean Theorem program:


Once you read and understand this Lesson you can call yourself a programmer when applying what you've learned. There's nothing new in the Pythagorean Theorem program except the use of logic and the use of a few arithmatic functions. Make sure you know why it works before continuing. I can't explain this any further, because then you wouldn't learn how to solve the 'Why and How' of logical operations yourself.

This concludes Lesson 2 "Pythagorean Theorem"
On to Lesson 3: Modes, Menus, and Linking

Any Errors need to be reported to William White.