$max_top_digits || $min_bottom_digits > $max_bottom_digits) { echo("

Error: Minimum number of digits can not be greater than the maximum number

\n"); return; } // Setup title and op symbol switch ($operation) { case 'addition': $title = "Addition"; $op = "+"; break; case 'subtraction': $title = "Subtraction"; $op = "-"; if ($min_bottom_digits > $max_top_digits) { echo("

Error: Simple subtraction can not have more digits in the second term

\n"); return; } break; case 'multiplication': $title = "Multiplication"; $op = "x"; break; case 'division': $title = "Division"; $op = "÷"; break; } $min1 = intval(substr("100000000",0,$min_top_digits)); $max1 = intval(substr("999999999",0,$max_top_digits)); $min2 = intval(substr("100000000",0,$min_bottom_digits)); $max2 = intval(substr("999999999",0,$max_bottom_digits)); if ($min1 == 1 && $operation != 'division') $min1 = 0; if ($min2 == 1 && $operation != 'division') $min2 = 0; // Display each page of questions $questions = array(); $num = 0; for ($p = 0; $p < $pages; $p++) { // Setup the questions for ($r = 0; $r < $numRows; $r++) { for ($q = 0; $q < $numQuestions; $q++) { $op1 = rand($min1,$max1); $op2 = rand($min2,$max2); $lcount = 0; while ($operation == 'subtraction' && $op2 > $op1) { $op2 = rand($min2,$max2); $lcount++; if ($lcount > 5) { $op1 = rand($min1,$max1); $lcount = 0; } } // Calculate the answer switch ($operation) { case 'addition': $ans = $op1 + $op2; break; case 'subtraction': $ans = $op1 - $op2; break; case 'multiplication': $ans = $op1 * $op2; break; case 'division': $val = $op1 * $op2; $ans = $op2; $op2 = $op1; $op1 = $val; break; } // Store the question terms $questions[$num]['1'] = $op1; $questions[$num]['2'] = $op2; $questions[$num]['ans'] = $ans; $num++; } } } // Display the questions only $num = 0; $tableStyle = "style='border: solid 1px #611A0B;'"; for ($p = 0; $p < $pages; $p++) { $page = $p + 1; ?> > \n"); for ($q = 0; $q < $numQuestions; $q++) { $op1 = $questions[$num]['1']; $op2 = $questions[$num]['2']; $ans = $questions[$num]['ans']; $num++; ?> \n"); } ?>
Math Worksheet - (Page )
 

$op $op2") ?>





 

> \n"); for ($q = 0; $q < $numQuestions; $q++) { $op1 = $questions[$num]['1']; $op2 = $questions[$num]['2']; $ans = $questions[$num]['ans']; $num++; ?> \n"); } ?>
Math Worksheet - Answers (Page )
 

$op $op2") ?>