Programming
245
Any statements between the end of the
RETURN
statement
and
END
are ignored.
On the Home screen (or in fact, anywhere in the
calculator where a number can be used), you can enter
ROLLDIE(6)
and a random integer between 1 and 6,
inclusive will be returned.
Another program could use the
ROLLDIE
function, and
generate
n
rolls of a die with any number of sides. In the
following program, the
ROLLDIE
function is used to
generate
n
rolls of 2 dice, each with the number of sides
given by the local variable sides. The results are stored
into the list L2, so that L2(1) shows the number of times the
dies came up with a 1, L2(2) shows the frequency of 2's,
etc. L2(1) should be 0 as a result.
Program ROLLMANY
EXPORT ROLLMANY(n,sides)
BEGIN
LOCAL k,roll;
// initialize list of frequencies
MAKELIST(0,X,1,2*sides,1)
L2;
FOR k FROM 1 TO n DO
ROLLDIE(sides) + ROLLDIE(sides)
roll;
L2(roll)+1
L2(roll);
END;
END;
This program uses a
FOR
loop, explained in the section
on loops.
A function's visibility can be restricted to within the
program where it is defined by omitting the
EXPORT
command when the function is declared. For example,
you could define the
ROLLDIE
function inside the
ROLLMANY
program like this:
EXPORT ROLLMANY(n,sides)
BEGIN
LOCAL k,roll;
// initialize list of frequencies
Содержание 39gII
Страница 1: ...HP 39gII graphing calculator user s guide Edition1 Part Number NW249 90001 ...
Страница 2: ...Printing History Edition 1 November 201 1 ...
Страница 32: ...22 Getting started ...
Страница 58: ...48 Apps and their views ...
Страница 70: ...60 Function app ...
Страница 80: ...70 Solve app ...
Страница 132: ...122 Parametric app your own table and the split screen functionality available in the Function app ...
Страница 136: ...126 Polar app ...
Страница 140: ...130 Sequence app ...
Страница 148: ...138 Finance app ...
Страница 152: ...142 Linear Solver app ...
Страница 218: ...208 Matrices ...
Страница 226: ...216 Notes and Info ...
Страница 238: ...228 Variables and memory management ...
Страница 318: ...308 Programming ...
Страница 340: ...330 Reference information ...
Страница 346: ...vi Product Regulatory Information ...