Posts tagged with “Plus”

TI-BASIC (Round Two) (Basic BASIC Input…and Math)

If you have a program that consists solely of displaying things, and it’s not some kind of thrilling narrative or story, then you have problems.
What you need is input.
So here’s how to do it:

Input X
Disp X

Wasn’t that tricky? When you run it, you’ll get a question mark (as in, “Yo! What do you want to input?”) and when you type something in (numbers only, for now), it’ll name the input ‘X’. Then you just ask it to display X.

(Input is in the same menu as Disp, if you’re having trouble finding it. Typing in I then N then P…etcetera, won’t work)

Now let’s do something (somewhat) useful:

Input L #L for length
Input W #W for width
Disp L*W

(NOTE: Everything after a # is a comment. Do not type it into the actual program, it’s just me explaining why I wrote a particular line the way it is. So what you should type in is:)

Input L
Input W
Disp L*W

There’ll be a ‘?’. You type in a number (length of rectangle). There’ll be another ‘?’. You type in another number (width of rectangle). It displays the product of the two numbers (area of rectangle).

In terms of function that ends our lesson on Input. However, I find the ‘?’s pretty ugly. Especially when you have several. So here’s the syntax for pretty-fying them.

Input "Length:",L
Input "Width:",W
Disp "Area is:",L*W

Here’s the output:

Length:3
Width:2
Area is:
                6

One more thing: the ‘Input’ function only accepts numbers. This can be lame if you want the person to, say, type in their name. (What’s your name? 1337)

The TI-86 has a different function called “InpSt” (Input String), which lets the user input a string of letters, not numbers. However, I’m pretty sure that the TI-83/84/80 families do not have this. Darn.

That’s all you need to know about Input to succeed in life :)

Now let’s talk about math. (Don’t worry, it’s a bit more interesting than normal math.) We’ve already touched on it, and the best way of explaining it is giving a sample program.

(Note: I’m going to use ‘->’ for the Store key throughout this entire guide. The Store key has Sto> written on it (the > is filled in though) and is used for assigning values to variables.)(I’ll also use sqrt() for the square root sign)

This program will solve for the hypotenuse of a right triangle.

Input "A:",A
Input "B:",B
A^2 + B^2->D
Disp "C squared is:",D
sqrt(D)->C
Disp "Hypotenuse is:",C

So the moral of the story (erm, program, I mean) is that you can do math with variables in programs.

Share/Save/Bookmark

Leave a Comment

TI-BASIC (Round One-and-a-Half) (Fun with Disp)

We touched on the Disp command in Round One. I’ve since realized that in my quest for simplicity, I didn’t say very much about it. So here are a few things (Every other line is the Disp command, and the other lines are the output)
Disp “2+2″
2+2
Disp 2+2
4
Disp “2+2″,2+2
2+2 (aligned left) [new line] 4 (aligned right)

Disp 2+2,2+2,2+2,3+2

4 [new line]4 [new line]4 [new line]5 [new line]

Output(1,1,”Hello World!”)

(Note: This is not Disp. This is Disp’s big brother Output. Output let’s you ‘plot’ the output on the screen. So the ‘1,1′ means that it puts the output in the first column and the first row.

Hello World!

So now you should have a better handle on the syntax

Share/Save/Bookmark

Leave a Comment

TI-BASIC (Round One) (Getting Started, Disp)

I’ve decided to make a tutorial/guide thing for TI-BASIC (that’s the programming language on Texas Instruments calculators) because….well, I want to. Hopefully people find it useful.
Before we get started with the mechanics of TI-BASIC, it’s important to say a few general things about programming:

1. There’s four main things that happen in a program. Input is what the user puts in. Output is what the calculator spits back out.
Control flow is what the programmer uses to adjust the ‘flow’ of a program (programs are ‘read’ from top to bottom, so you need to specifically state when it shouldn’t be), and finally ‘operations’ (I just made that term up) that let you modify the input and output.
2. It’s very important to know what you want a program to do before you make it. It’s no good to say “I want it do check my answers for math class”. You need to say “I want it to ask me for two numbers, add the two numbers together, and then display the result.”
3. Thinking is required. All of it doesn’t just come naturally, sometimes you need to sit down and think out what the best way of doing something is.

So, that said, let’s start with–well, how to make and run a program on your calculator.
Turn your calculator on (a lot of this is easy.) And press the PRGM on it. If you have a TI-86/85, press F2 (Edit), and type in a new name for your program. If you’re using a TI-80/81/82/83/83+/83+SE/84+/84+SE, scroll over to the “Create New” tab, and type in a new name. (Note: I didn’t include TI-89s in the list because I don’t have one. If you send me one, I’d be more than happy to include it in this guide :) After you type in the name, and press ENTER, you’ll see a screen that says
PROGRAM:A NAME
:

Where A NAME is the name you typed in.

Pressing QUIT will exit the Programming screen, save the program, and return you to the home screen all in one.

So now that that’s taken care of, let’s write a simple program. There’s a tradition among programmers to always use “Hello World!” as a first program. So
open up a new program and call it HELLO. Now let’s take a moment and think about this. You want the program to say “Hello World!” when it’s run. That’s output. There’s no input necessary. You don’t need to control the flow, because the calculator doesn’t need to react differently to anything, and finally, since there’s no input, no operations need to take place.

So press the PRGM button again. You should see a menu labelled Ctl, that has stuff like If, While, For, End, etc. Scroll over one, to the I/O menu, and select the Disp option. Disp stands for “Display”, and is the command to display something on the screen. After the Disp, type in: “Hello World!”. Now your calculator knows to display something, and it knows the thing to display is ‘Hello World!’.


PRGM: HELLO
:Disp “HELLO WORLD!”

Run the program by quitting, hitting PRGM, and selecting ‘HELLO’. This’ll paste something onto your home screen. Press ENTER to run the program.


prgm_HELLO
HELLO WORLD!
Done

Round two: Basic BASIC input and math.

Share/Save/Bookmark

Leave a Comment