
-----------------------------------
stef_ios
Mon Apr 02, 2007 3:05 pm

Dice Roll
-----------------------------------
So i'm doing a dice rolling program. I want a single di to roll, and when the same number has been rolled, i want the program to stop and output the number that was rolle twice and the number of rolls it took to get that number to roll twice. I know it's simple. Here is the code I have so far: 


var dice, sum : int
var roll : string
var test : string
var num_rolls : int
var freq : array 1 .. 12 of int
var answer : string

loop
    randomize

    var Num_Rolls : int

    for i : 1 .. 12
        freq (i) := 0
    end for

    for i : 1 .. 12
        dice := Rand.Int (1, 6)
    end for

    put "The number rolled twice was: " ..
    put skip
    put "The number of rolls it took to roll this number twice was: " ..
    put skip
var response: string
    
put "Do you want to roll again? (Y= yes, N= no)"
get response
put skip
exit when response="N" or response="n" or response="NO" or response="no"
end loop


Now the only thing I need help with is the part of the code that knows what number the dice lands on. I know I need to use randomize, but i'm not exactly sure what the code is, and where to put it in my program. Any help I could get wou;d be great! Thanks!

-----------------------------------
Clayton
Mon Apr 02, 2007 4:31 pm

RE:Dice Roll
-----------------------------------
Well, have a variable to keep track of what number  Rand.Int returns, print it out on the screen, and then "roll" the dice again.

-----------------------------------
nikoudov
Sun Apr 15, 2007 5:24 pm

RE:Dice Roll
-----------------------------------
just add in "rand.int (x,y)" etc... and add in the useful variables to correspond with your dice rolls.
