Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Dice rolling...
Author Message
Squirter

Posted: Mon Jan 26, 2004 6:39 pm   Post subject: Dice rolling...

I'm trying to generate a number for a 20-sided die being rolled a certain amount of times.

 code: 20-sided die \$rolls times.
"; echo "The outcome is \$outcome"; ?>

Problem is, I want it to make a random number for each roll. Right now, it only gets one number, and multiplies it by the number of rolls I requested.

e.g Set to roll 3 times. First it rolls a 4. But then it multiplies itself by 3. 4 * 3 = 12.

I want it to make a different number each time, so:

Set to roll 3 times. 5 + 17 +12 = 34.

Anyone know the problem?
(BTW, I'm pretty new to PHP, so if you put in a new command, could you explain it? ^^

octopi

Posted: Mon Jan 26, 2004 8:27 pm   Post subject: (No subject)

I think you want to roll the dice, the number of times specifiyed by 'rolls'

consider the following:

 code: \n";  } ?>

the 'for' command loops the number threw the stuff in the {}'s the number of times specified by the '\$x=1;\$x <= \$rolls; \$x+=1', this says....the first time we enter the for loop, set x=1, then the next parts the condition, it keeps looping until this is false, and the next parts the counter, this increments x by 1, each time, until it meets the condition.
Squirter

Posted: Tue Jan 27, 2004 10:05 pm   Post subject: (No subject)

Er, I didn't really understand that...
Could you give me another example?

BTW, what is <=?

Posted: Wed Jan 28, 2004 3:17 pm   Post subject: (No subject)

<= is just less than or equal to... same as in any boolean comparison expression in any language
wtd

Posted: Sat Feb 14, 2004 12:13 am   Post subject: (No subject)

Just for the sake of havng an OO solution.

 code: sides = \$sides;       }       function roll() {          return rand(1, \$sides);       }    }    \$rolls = \$HTTP_GET_VARS['rolls'];    \$die = new Die(20);    for (\$i = 1; \$i <= \$rolls; \$i++) {       echo('You rolled ' . \$die->roll() . '
');    } ?>
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 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: