Back to DFS's Workshop Page
Back to Agenda Page
Tabulating Dice Rolls
For this problem, you are to cannibalize any available code and write a pair of scripts which will do the following.
- The HTML Page: dicerolls.html
- Ask the user for the number of rolls of two six-sided dice
- Accept input in a form
- Using the "Roll" button, send the data to a PHP script called dicerolls.php
- The PHP Script: dicerolls.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 could 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 dispayed.
© 2004-2005 DFStermole
Created 2 May 04
Last Modified 13 Nov 05