462
Programming
•
start the app
•
specify the number of sides (that is, faces) on each
die
•
specify number of times to roll the dice
•
start the app again.
With that in mind, we will create the following views:
START
,
SETSIDES
, and
SETNUMROLLS
.
The
START
option will initialize the app and display a
note that gives the user instructions. The user will also
interact with the app through the Numeric view and the
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;
Summary of Contents for NW280-200X
Page 1: ...HP Prime Graphing Calculator User Guide ...
Page 4: ......
Page 56: ...50 Reverse Polish Notation RPN ...
Page 64: ...58 Computer algebra system CAS ...
Page 107: ...An introduction to HP apps 101 ...
Page 108: ...102 An introduction to HP apps ...
Page 188: ...182 Spreadsheet these variables is provided in chapter 21 Variables beginning on page 373 ...
Page 220: ...214 Statistics 2Var app ...
Page 252: ...246 Linear Solver app ...
Page 258: ...252 Parametric app ...
Page 268: ...262 Sequence app ...
Page 404: ...398 Units and constants ...
Page 416: ...410 Lists ...
Page 442: ...436 Notes and Info ...
Page 532: ...526 Limiting functionality ...
Page 536: ...530 ...
Page 540: ...534 ...