EPOC   SDK Home Glossary   Previous Next Up

Dice — Rolls dice

When the program is run, a message is displayed saying that the dice is rolling. You then press a key to stop it. A random number from one to six is displayed and you choose whether to roll again or not.

    PROC dice:
          LOCAL dice%
          DO
                CLS :PRINT "DICE ROLLING:"
                AT 1,3 :PRINT "Press a key to stop"
                DO
                      dice%=(RND*6+1)
                      AT 1,2 :PRINT dice%
                UNTIL KEY
                BEEP 5,300
                dINIT "Roll again?"
                dBUTTONS "No",%N,"Yes",%Y
          UNTIL DIALOG<>%y
    ENDP

Random numbers

In this example, the RND function returns a random floating-point number, between 0 and 0.9999999... It is then multiplied by 6, and 1 is added, to give a number from 1 to 6.9999999... This is rounded down to a whole number (from 1 to 6) by assigning to the integer dice%.

EPOC       SDK Home Glossary   Previous Next Up