You are on page 1of 2

Mariana Torres

4th Form

<!--Program Name: Calculator-->


<!--Program Date: Feb 15th, 2015-->
<!--Program Author: Mariana Torres-->
<!--Program Purpose: Homework-->
<html>
<body bgcolor="#204479"> <!--Background Color-->
<center> <!--Aligns the words in the middle-->
<h2>
<font color="99FFF"> <!--Background Color-->
<form action="calu.php" method="post">
Num1 <input name="num1" type="text"/> <!--user must enter a second number-->
Num2 <input name="num2" type="text"/> <!--user must enter a second number-->
<p>
<legend><h1><u> Choose an Operation:</legend></h1></u>
<select name="operations"/>
<option>+</option> <!--Addition option-->
<option>-</option> <!--Subtraction option-->
<option>*</option> <!--Multiplication option-->
<option>/</option> <!--Divide option-->
<option>Sqr</option> <!--Square option-->
<option>Sqrtroot</option> <!--Squareroot option-->
</select>
</p>
<input type="submit" value="Click to Calculate"/><!--When Clicked, it calculates for your answer--
>
</form>
</center>
<?php
$choice= $_POST['operations']; //variable declaration
$num1= $_POST['num1'];
$num2= $_POST['num2'];
function add($num1,$num2){ //addition function
$total=$num1+$num2;
return $total;
}
function minus($num1, $num2){ //subtract function
$total= $num1 - $num2;
return $total;
}
function mul($num1, $num2){ //multiplication function
$total= $num1 * $num2;
return $total;
}
function div($num1, $num2){ //divison function
$total= $num1 / $num2;
return $total;
}
function square($num1){ //square function
$total= $num1 * $num1;
return $total;
}
function sqroot($num1){ //squareroot function
$total= sqrt($num1);
return $total;
}
if($choice=="+"){ //If choice is chosen, it calls down the add function.
$ans=add($num1,$num2);
echo "Your answer is : ".$ans;
}
if($choice=="-"){ //If choice is chosen, it calls down the subtract function.
$ans=minus($num1,$num2);
echo "Your answer is : ".$ans;
}
if($choice=="*"){ //If choice is chosen, it calls down the multiplcation function.
$ans=mul($num1,$num2);
echo "Your answer is : ".$ans;
}
if($choice=="/"){ //If choice is chosen, it calls down the division function.
$ans=div($num1,$num2);
echo "Your answer is : ".$ans;
}
if($choice=="Sqr"){ //If choice is chosen, it calls down the square function.
$ans=square($num1);
echo "Your answer is : ".$ans;
}
if($choice=="Sqrtroot"){ //If choice is chosen, it calls down the squareroot function.
$ans=sqroot($num1);
echo "Your answer is : ".$ans;
}
?>
</body></html>

You might also like