Back to DFS's Workshop Page
Back to Agenda Page
Binary Subtraction 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 subtraction. Your scripts are to do the following.
- The Question Page: binsubquestion.php
- Pose a binary subtraction problem, generating random values for the minuend and subtrahend
- Accept the answer as input in a form
- Using a "Check It" button, send the data to a PHP script called binsubanswer.php
- The Answer Page: binsubanswer.php
- Present a solution to the problem, indicating the borrows with red digits
- 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 quinary, octal and hexadecimal.
Notes
- 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 borrow digits.
- If you attempt the slightly more complex hexadecimal version, you may want to use the strtoupper() and strval() functions.
© 2007 DFStermole
Created 1 Jan 07
Last Modified 1 Jan 07