244
Programming
The
EXPORT
command for
the variable
RADIUS
must
appear before the heading
of the function where
RADIUS
is assigned. After
you execute this program,
a new variable named
RADIUS
appears on the
USER
GETRADIUS
section of the Vars menu.
Functions, their
arguments, and
parameters
The programming environment for the HP39gII is highly
structured. You can define your own functions in a
program, and data can be passed to a function using
parameters. Functions can return a value (using the
RETURN
statement) or not. When a program is executed
from Home, the program will return the value returned by
the last statement that was executed.
Furthermore, functions can be defined in a program and
exported for use by other programs in the same way that
this is done for variables. This feature makes the HP39gII
an incredibly powerful programming platform.
In this section, we will create a small set of programs,
each illustrating some aspect of programming on the HP
39gII. Each of these programs will be used as a building
block for a custom app described in the next section,
App
Programs
.
Here is a program that defines a function called
ROLLDIE
that simulates the rolling of a single die,
returning a random integer between 1 and whatever
number is passed into the function:
First, create a new program named
ROLLDIE
. Then
enter the program.
Program ROLLDIE
EXPORT ROLLDIE(N)
BEGIN
RETURN 1 + FLOOR(N*RANDOM);
END;
The first line is the heading of the function. Execution of
the
RETURN
statement causes a random integer from 1 to
N to be calculated and returned as the result of the
function. Note that execution of a
RETURN
command
causes execution of the function to terminate.
Summary of Contents for 39gII
Page 1: ...HP 39gII graphing calculator user s guide Edition1 Part Number NW249 90001 ...
Page 2: ...Printing History Edition 1 November 201 1 ...
Page 32: ...22 Getting started ...
Page 58: ...48 Apps and their views ...
Page 70: ...60 Function app ...
Page 80: ...70 Solve app ...
Page 136: ...126 Polar app ...
Page 140: ...130 Sequence app ...
Page 148: ...138 Finance app ...
Page 152: ...142 Linear Solver app ...
Page 218: ...208 Matrices ...
Page 226: ...216 Notes and Info ...
Page 238: ...228 Variables and memory management ...
Page 318: ...308 Programming ...
Page 340: ...330 Reference information ...
Page 346: ...vi Product Regulatory Information ...