Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Help with random number program
Author Message
JR

Posted: 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?

santabruzer

Posted: 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

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

k thx alot
Cervantes

Posted: 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

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

bah im such a noob in turing. i got another question.
 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

Posted: 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

Posted: 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

Posted: 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

Posted: 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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 9 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: