";
}
else if ($mathOp == "subtract")
{
$result = $argument1 - $argument2;
//echo "result is $result
";
}
else if ($mathOp == "multiply")
{
$result = $argument1 * $argument2;
//echo "result is $result
";
}
else if ($mathOp == "divide")
{
if ( $argument2 != 0 )
{
$result = $argument1 / $argument2;
//echo "result is $result
";
}
else
{
$errorStr = "Error: cannot divide by zero.";
}
}
else
{
$errorStr = "Error: please select math option.";
}
return $result;
} /* end function checkInput */
/* Only run this code if the user has submitted the values &
operation for calculation. */
if (isset($_GET['submit']))
{
//print_r($_GET);
/* Verify that the user entered the first value to apply the
mathematical operation on. */
if (isset($_GET['argument1']))
{
$argument1 = $_GET['argument1'];
}
else
{
$errorStr = "Please enter a number to calculate.";
}
/* Verify that the user entered the second value to apply the
mathematical operation on. */
if (isset($_GET['argument2']))
{
$argument2 = $_GET['argument2'];
}
else
{
$errorStr = "Please enter a second number to calculate.";
}
/* Verify that the user entered calculation operation to apply. */
if (isset($_GET['operation']))
{
$operation = $_GET['operation'];
}
else
{
$errorStr = "Please enter an operation for calculation.";
}
if ( empty($errorStr))
{
$answer = doMath ($operation, $argument1, $argument2, &$errorStr);
}
}
?>