Example Program: DICE

Top  Previous  Next

This little program uses an integer array to represent the six sides of a die. The program simulates throwing the die 10000 times and counts the number of times each side lands up. The sides are numbered 0 through 5 in the array.



        \This program simulates dice throwing

        code  Ran=1, ChOut=8, CrLf=9, IntOut=11;

        integer Side(6), I, N;



        for I:= 0, 5 do Side(I):= 0;    \Initialize array with zeros

        for I:= 1, 10000 do             \Throw the die 10000 times


                N:= Ran(6);             \Randomly pick a side

                Side(N):= Side(N) + 1;  \Increment counter for side


                                        \Show the results

        for I:= 0, 5 do [IntOut(0, Side(I));   ChOut(0, \tab\$09)];





Running this program produced the following output:


        1701    1715    1711    1665    1601    1607