Back to DFS's Workshop Page
Back to Agenda Page
Tabulating Dice Rolls II
For this problem, you are to cannibalize any available code and write a pair of scripts which will do the following.
- The HTML Page: nsideddicerolls.html
- Ask the user for the number of sides for the dice
- Ask the user for the number of rolls of two such dice
- Accept input in a form
- Pass a hidden value for the maximum number of sides and one for the maximum number of rolls
- Using the "Roll" button, send the data to a PHP script called nsideddicetable.php
- The PHP Script: nsideddicetable.php
- Check the data received to ensure that the value is possible; use die or exit to report problems and terminate execution
- Tell the user how many rolls were requested
- Simulate the rolling of the dice using the rand function (see also Generating Random Values), storing the values in a pair of arrays
- Calculate the sum of each roll of the pair of dice, storing the results in an array
- Calculate the means for the rolls of each die and for the sums of each pair
- Print a table which specifies six things:
- Labels for the columns
- The number of the roll in the first column
- The first die in the second column
- The second die in the third column
- The sum of the dice in the fourth column
- The means of the second, third, and fourth columns in the last row
To see how this should work, view this possible solution.
Notes
- Some browsers are pickier in their insistence that HTML code adhere to the language's syntax rules. Failure to terminate a table with the </table> tag may result in nothing being displayed.
© 2006 DFStermole
Created 19 Oct 06
Last Modified 8 Nov 07