Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with random number program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JR




PostPosted: Tue Feb 03, 2004 5:15 pm   Post subject: Help with random number program

hey, i'm new to the site.
i got a problem with a program, i need to to make 10 random numbers but with one program. thats what i got for now.
code:
var x,n1,n2,count:int
put " choose your low number "
get n1
put " choose your hight number "
get n2
randint (x,n1,n2)
count:=1
put " you got ", x
loop
randint (x,n1,n2)
if count:=10 then exit
end if
end loop


any tips?
Sponsor
Sponsor
Sponsor
sponsor
santabruzer




PostPosted: Tue Feb 03, 2004 5:22 pm   Post subject: (No subject)

here's your prog.. just a abit changed.. i say for statement is better.. but just continuing what you did:

code:
var x, n1, n2, count : int
put " choose your low number "
get n1
put " choose your hight number "
get n2

count := 1

loop
    randint (x, n1, n2)
    put " you got ", x
    randint (x, n1, n2)
    count += 1
    if count = 10 then
        exit
    end if
end loop
JR




PostPosted: Tue Feb 03, 2004 5:28 pm   Post subject: (No subject)

k thx alot
Cervantes




PostPosted: Tue Feb 03, 2004 5:35 pm   Post subject: (No subject)

for clarification and cleaning things up.

code:
count += 1

is the same as
code:
count := count + 1


also you don't need to have randint twice inside the loop, get rid of the lower one.

also, though this works
code:

    if count = 10 then
        exit
    end if


it saves you code to just put

code:
exit when count = 10
JR




PostPosted: Tue Feb 03, 2004 5:51 pm   Post subject: (No subject)

bah im such a noob in turing. i got another question.
i made this program
code:

var x,y,count:int
randint (x,1,6)
randint (y,1,6)
put " your dice roll is ", x+y
count := 1

loop
    randint (x, 1, 6)
    randint (y, 1, 6)
    put " you got ", x+y
    randint (x, 1, 6)
    count += 1
    if count = 100 then
        exit
    end if
end loop



now i figured out how to do 100 dice rolls, my problem is how do i set how many vars of each number where used? like if there was 20 1's 20 2's ect how do i find how many 1-6 there was?
Cervantes




PostPosted: Tue Feb 03, 2004 6:09 pm   Post subject: (No subject)

you could use an array to make 100 vars, but you don't need to do that

use a for statement.. santa mentioned them earlier.



var howmany : int
put "How many times would you like to roll the dice? : " ..
get howmany

code:
var roll : int
var one, two, three, four, five, six : int := 0

for i : 1 .. howmany

    randint (roll, 1, 6)
    if roll = 1 then
       one += 1
    end if
    if roll = 2 then
       two += 1
    end if
    if roll = 3 then
       three += 1
    end if
    if roll = 4 then
       four += 1
    end if
    if roll = 5 then
       five += 1
    end if
    if roll = 6 then
       six += 1
    end if
   
    put "Roll : ", roll
   
end for

cls
put "One's : ", one
put "Twos's : ", two
put "Three's : ", three
put "Four's : ", four
put "Five's : ", five
put "Six's : ", six


that's only for rolling 1 die though.. you can alter that prog so that you can roll 2 dies and add them together and determine how many of what you get.
Andy




PostPosted: Tue Feb 03, 2004 8:32 pm   Post subject: (No subject)

y dont u have arrays? just go dice(Rand.Int(1,6))+=1
santabruzer




PostPosted: Tue Feb 03, 2004 8:40 pm   Post subject: (No subject)

*whistles*...

code:
var dice : array 1 .. 6 of int := init (0, 0, 0, 0, 0, 0)
for i : 1 .. 100
    dice (Rand.Int (1, 6)) += 1
end for
cls
put "One's : ", dice (1)
put "Twos's : ", dice (2)
put "Three's : ", dice (3)
put "Four's : ", dice (4)
put "Five's : ", dice (5)
put "Six's : ", dice (6)
Thuged_Out_G




PostPosted: Wed Feb 04, 2004 8:41 pm   Post subject: (No subject)

dammit, i never even thought of that...i did the same program...but i used 6 different for loops i think...ill post the method i did later on so you can all laugh at it Laughing
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: