Saturday, March 9, 2013

HP 39gii Programming Part 1: INPUT, PRINT, string



Welcome to our HP 39gii Programming Boot Camp!

This is a six part tutorial series in order to get you started programming with the Hewlett Packard HP 39gii calculator. The language may be quirky and imperfect, but rest assured you can still accomplish many things with this programming language.

You can download the emulator here: http://www.hp.com/sbso/product/calculators-emulators/graphic-calculator-emulators.html. It works with Windows, it should work with the Mac (please don't quote me on this).


Contents
1. Creating a Program
2. Structure of a Program
3. The Program AREACIR
4. Running Programs
5. Running AREACIR
6. PRINT, INPUT, and string

Let's get started with our first program, AREACIR. If you guessed that this calculated the area of a circle, you are correct. Gold star for you!


1. Creating a Program
1. Press [SHIFT] [ 1 ] (PRGM).
2. Press [ F2 ] (NEW).
3. Enter the name of your new program. Use [ALPHA] for a single letter, [ALPHA] [ALPHA] to force alphabetical lock, and [SHIFT] to type lower case letters.
4. Press either [ENTER] or [ F6 ] (OK). You are off and running!


2. Structure of a Program
The general structure of a program is:

EXPORT NAME(pass-through arguments)
BEGIN
Commands;
END;


A semicolon (;) follows the end of MOST program lines, all storing commands, and mathematical calculations.

Any arguments that are passed through the program name are designated local variables. Local variables are variables that are used in the program and deleted when done. Global variables are variables that can be accessed inside and outside programming. The HP 39gii restricts the types of global variables.

Type of global variables:
Real: A through Z, θ
Matrices: M0 through M9
Lists: L0 through L9
Complex Numbers: Z0 through Z9

Almost everything else, including strings, must be local variables. To declare any variable, including global variable types, type:

LOCAL var, var, var, ...;

Include as many variables as you want. When you select LOCAL from the Cmds menu, it will give you a set parenthesis. Erase them, LOCAL does not work with parenthesis.

Let's get to our first program, AREACIR. AREACIR will have one pass-through argument, the radius.


3. The Program AREACIR
EXPORT AREACIR(R)
BEGIN
π*R²;
END;


This program returns the area of a circle to the home screen.


4. Running Programs

You can run programs from two places: the Home Screen or thought the Program Catalog. I recommend the former (Home Screen) if you have pass-through arguments.

From the Home Screen:

1. Press [Home]
2. Press [SHIFT] [Math] (Cmds)
3. Press [ F3 ] (USER)
4. Find the program you want to run, pressing [ENTER] or [ F6 ], twice.
5. If any pass-through arguments are required, include the parenthesis and arguments. Otherwise, just press [ENTER].

You may also type out the program's with any required arguments.


5. Running AREACIR

Find the area of the circle with radius 17.5 units.

Using the Cmds menu from Home:

1. Press [Home]
2. Press [SHIFT] [Math] (Cmds)
3. Press [ F3 ] (USER)
4. Find the program you want to run, pressing [ENTER] or [ F6 ], twice.
5. Press [ ( ] 17.5 [ ) ] [ENTER]

Alternatively, you can type AREACIR(17.5) [ENTER]

The area is approximately 962.112750162.


6. PRINT, INPUT, and string

Our next program will do the same as AREACIR, except instead of using pass-through arguments, we will use prompting and displaying answers on an output terminal.

INPUT

Keystrokes: [SHIFT] [Math] [ F1 ] [ 5 ] [ 6 ]
Command can be typed
Basic Syntax: INPUT(global variable, "title string");

INPUT can have more arguments, check the HP 39gii manual. INPUT only works with one variable at a time and works only variables that can be global. INPUT does not work when promoting for strings.

In practice, I recommend that you use pass-through arguments instead of INPUT.

PRINT

Keystrokes: [SHIFT] [Math] [ F1 ] [ 5 ] [ 9 ]
Command can be typed
Basic Syntax: PRINT(string of text);

Note that strings of text are connected with the + operator.

string

This commands evaluates a mathematical expression and makes the result a string. This is useful for displaying text with mathematical calculations.

Keystrokes: [SHIFT] [Math] [ F1 ] [ 8 ] [Vars]
Command can be typed, but the command must be typed in lowercase!
Basic Syntax: string(mathematical expression or result);

Let's use INPUT, PRINT, and string in a program:

The Program AREA1:

EXPORT AREA1()
BEGIN
INPUT(R, "Radius");
PRINT("THE AREA IS " + string(π*R²) + ".");
END;


Running AREA1: Type or call AREA1 at the Home Screen. Since there are no pass-through arguments, you won't need parenthesis.

You will be prompted for R. If I enter 17.5 at the prompt, I will get a screen that contains the message:

THE AREA IS 962.112750162.

When you press ENTER, that string will be returned to the Home screen.


Part 2: IF-THEN-ELSE, MSGBOX, and CHOOSE.

Have a great day!


Eddie


This blog is property of Edward Shore. 2013

Sum of Sequential Integers (featuring Swiss Micros DM32)

  Sum of Sequential Integers ( featuring Swiss Micros DM32) What is the sum of the following: 100 + 101 + 102 + 103 + 104 + 105 + … + ...