beautypg.com

HP Prime Graphing Calculator User Manual

Page 527

background image

Programming

523

Plot view. These views will be activated by pressing

M

and

P

, but the functions Num and Plot in our app

program will actually launch those views after doing some
configuration.
The program discussed earlier in this chapter to get the
number of sides for a dice is expanded here, so that the
possible sums of two such die are stored in dataset D1.
Enter the following sub-routines into the program for the
DiceSimulation app.

The program

DiceSimulation

START()
BEGIN
DICESIMVARS();
{}

D1;

{}

D2;

SetSample(H1,D1);
SetFreq(H1,D2);
0

H1Type;

END;
VIEWS "Roll Dice",ROLLMANY()
BEGIN
LOCAL k,roll;
MAKELIST(X+1,X,1,2*SIDES-1,1)

D1;

MAKELIST(X+1,X,1,2*SIDES-1,1)

D2;

FOR k FROM 1 TO ROLLS DO
roll:=ROLLDIE(SIDES)+ROLLDIE (SIDES);
D2(roll-1)+1

D2(roll-1);

END;
-1

Xmin;

MAX(D1)+1

Xmax;

0

Ymin;

MAX(D2)+1

Ymax;

STARTVIEW(1,1);
END;
VIEWS "Set Sides",SETSIDES()
BEGIN
REPEAT