Back to DFS's Workshop Page
Back to Agenda Page
Quinary Money Addition Problem
For this problem, you are to cannibalize any available code and write a pair of scripts to serve as a quiz on quinary (base 5) addition. Your scripts are to do the following.
Pennies, nickels and quarters are used to represent the values of the quinary addends.
- The Question Page: quinaddquestion.php
- Pose a quinary addition problem, generating random values for the addends; the values are to be given as coins, the equivalent as dollars and cents, and quinary numbers
- Accept the user's answer as input in a form
- Allow the user to set in the form the length of time each intermediate page will be displayed; use a reasonable default value
- Using a "Check It" button, send the data to a PHP script called quinaddanswer.php
- The Adding-Process and Answer Pages: quinaddanswer.php
- Recursively call this script to illustrate the addition of the columns, moving from right to left; intermediate values should be given as both coins and dollars and cents; carrying should be demonstrated as two steps in the process
- The intermediate steps should be shown for the length of time the user specified on the starting page; see the Recursive Factorial page regarding the use of the meta tag in the HTML head
- When the correct sum is achieved by the simulator, present a mathematical solution to the problem, indicating the carries with red 1s
- Evaluate the user's answer
- If the user's answer is correct, let him know
- If the user's answer is incorrect, print the user's answer, indicating which digits are not right
To see an implementation which you could reverse engineer, view this possible solution. You can also view a solution which includes quinary number circles. As an alternative problem, you could implement an equivalent set of scripts using graphics for binary, octal, or hexadecimal.
Notes
- Instructions on how to use the programs must be included.
- Use the rand() function to generate the values for the addends.
- The base_convert() function may be useful.
- The HTML <PRE> tag and the str_pad() and str_repeat() functions can be used to align the numbers.
- Since values from an HTML form are passed as strings, and strings can be treated as subscripted arrays, looping structures can be used to handle the individual binary digits and the carry digits.
- If you attempt the slightly more complex hexadecimal version, you may want to use the strtoupper() and strval() functions.
© 2007 DFStermole
Created 16 Nov 07
Last Modified 17 Nov 07