Problem 4-11 Solution

<?php
/*
 * Created on Feb 11, 2008
 *
 * Exercise 4-11 page 84
 */
?>
<HTML>
  <HEAD>
    <TITLE>Math Example</TITLE>
  </HEAD>
  <BODY>
    <H4>One of Four Operations</H4>
    <?php
       $x = 10;
       $n = 5;
       $m = rand(1,4);;
       echo "Choosing random operation $m<br>";
       switch ($m) {
           case 1:
             $result = $x+$n;
             echo "Addition: $x + $n equals = $result<br>";
             break;
           case 2:
             $result = $x-$n;
             echo "Subtraction: $x - $n equals = $result<br>";
             break;
           case 3:
             $result = $x*$n;
             echo "Multiplication: $x * $n equals = $result<br>";
             break;
           case 4:
             $result = $x/$n;
             echo "Division: $x / $n equals  $result<br>";
             break;
           default:
      	     echo "$m is not a legal option<BR>";
      	 }
    ?>
  </BODY>
</HTML>