Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

TI Source: Variables
 
 Path: Home - Basic - Variables    
  Basic    Assembly    Interactive    Miscellaneous    Members  

  Guide    Glossary    Programs  
 VariablesBy Justin 
You probably already know what a variable is in math. It is a letter that represents a value.

To demonstrate what a variable is in programming I will use the classic example of a box. Think of a variable as a little box inside the calculator that stores the value you want it to. You can manipulate the value in this box. For example, you can add one variable to another and store the sum in a third variable.

There are a few rules you must remember when working with variables.

  1. The name of the variable must be a letter (A-Z)
  2. It can be no longer than one letter long
  3. When assigning a value to a variable you must follow this syntax:

    value -> variable

The following example demonstrates how to assign a value to a variable:

Notice that the variable name is on the right of the value. You must have it in this order (value = variable).

Breakdown of code:

10 -> A
Give the value "10" to the variable "A."
10+10 -> B
Give the value of "10+10" to the variable "B." B = 20
Disp A
Display the value of the variable "A." Notice you do not need the put "" around the A.
Disp B
Display the value of the variable "B."

Program output:

It is very useful to know how to manipulate variables. You can add, subtract, multiply and divide variables.

The following is an example of adding variables.

Breakdown of code:

10 -> A
A = 10
10 -> B
B = 10
B+A -> C
A(10) + B(10) = C. C = 20
Disp C
Display C

Program output:

Remember that you can also subtract, multiply and divide variables.

A very useful way to use variables is to count. For example, in a shooting game, you may want to count how many times the user shoots down a ship and then show the score. You would have to assign a variable for the score. Then, every time a ship is shot you would have to increase that variable by one.

Here is an example of how you could increase the variable:

Breakdown of code:

1 -> A
A = 10
1 + A -> A
1 + A(1) = A. This will simply increase the value of A by 1.

Program output:

Program ideas:

Take a look at random numbers, and the Output command. Make a program that will display a word at a random position on the screen.

First try to make it yourself, then you can download an example of this program below. (It is the one marked Program idea)

 Downloads:
TitleDescriptionAuthor
variables.zipAll filesJustin
randtext.zip- Program idea -Justin
var.zipAssign a value to a variable.Justin
varadd.zipAdd two variables together.Justin
countvar.zipIncrease variable by one.Justin
  Basic    Assembly    Interactive    Miscellaneous    Members