May not be exactly what you wanted, but I've made a generator. Just paste the code and test it out:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Maths Generator</title>
<?php
$gen1 = mt_rand(1,9);
$gen2 = mt_rand(1,9);
$gen3 = mt_rand(1,9);
$operators = array("+", "-", "/", "*");
$rand = mt_rand(2, 3);
$rand2 = mt_rand(0, 1);
echo $gen1 . " " . $operators[$rand] . " " . $gen2 . " " . $operators[$rand2] . " " . $gen3 . "<br />";
switch ($operators[$rand])
{
case "*":
$first = $gen1 * $gen2;
break;
case "/":
$first = $gen1 / $gen2;
break;
}
switch ($operators[$rand2])
{
case "+":
$second = $first + $gen3;
break;
case "-":
$second = $first - $gen3;
break;
}
$answer = $second;
echo $answer;
?>
</body>
</html>
As you can see, the first two operators are higher in BODMAS, so you never have the problem of having the sum done in the wrong way.
Doing it another way would be a bit more complicated, hope this helps
Bookmarks