Calculations in a program, Structured programming – HP 48g Graphing Calculator User Manual

Page 410

Attention! The text in this document has been recognized automatically. To view the original document, you can use the "Original mode".

Advertising
background image

So the following program takes two numbers from the stack and
returns a numeric result:

a b

3-b:

Calculations in a Program

Many calculations in programs take data from the stack—sometimes

put there by the user or by another program. Here are two typical
ways to manipulate that data:

B Stack commands. Operate directly on the objects on the stack.
B Local variable structiu^e. Stores the stack objects in temporary local

variables, then uses the variable names to represent the data in the

following algebraic or program object.

Numeric calculations provide convenient examples of these methods.

The following three programs use two numbers from the stack

to calculate the hypotenuse of a right triangle using the formula

d

Q SNM.

h

SQ

S Q y

-I"

29

The first program uses stack commands to manipulate the numbers

on the stack—the calculation uses stack syntax. The second program

uses a local variable structure to store and retrieve the numbers—the
calculation uses stack syntax. The third program also uses a local
variable structure—the calculation uses algebraic syntax. Note that
the underlying formula is most apparent in the third program.

Local variable structures with algebraic objects are favored by many

programmers because they’re easy to write, easy to read, and simple
to debug.

Structured Programming

The HP 48 encourages structured programming. Every program has
only one entrance point—the beginning of the program. It also has
only one exit point—the end of the program. There are no labels
inside a program to jump to—there are no GOTO commands to exit

from. From an external point of view, program flow is extremely

simple—start at the beginning, stop at the end. (Of course, inside the

29-4 Programming the HP 48

Advertising
This manual is related to the following products: