The program
DiceSimulation
462
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
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.
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)
MAKELIST(X+1,X,1,2*SIDES-1,1)
FOR k FROM 1 TO ROLLS DO
roll:=ROLLDIE(SIDES)+ROLLDIE (SIDES);
D2(roll-1)+1
END;
D2(roll-1);
M
D1;
D2;
Programming