Back to DFS's Workshop Page
Back to Agenda Page
Binary Multiplication Problem
For this problem, you are to cannibalize any available code and write a pair of scripts to serve as an incipient quiz on binary multiplication. Your scripts are to do the following.
- The Question Page: binmultquestion.php
- Pose a binary multiplication problem, generating random values for the multiplicand and multiplier
- Accept the answer as input in a form
- Using a "Check It" button, send the data to a PHP script called binmultanswer.php
- The Answer Page: binmultanswer.php
- Present a solution to the problem, including intermediate products
- 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 how this could work, view this possible solution. You can also view solutions for octal and hexadecimal.
Notes
- Use the rand() function to generate the values for the multiplicand and multiplier.
- 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.
- If you attempt the slightly more complex hexadecimal version, you may want to use the strtoupper() and strval() functions.
© 2006 DFStermole
Created 6 Jan 06
Last Modified 6 Jan 06