The document describes a calculator program created by Mariana Torres for a homework assignment. The program allows users to input two numbers and select an operation to perform - addition, subtraction, multiplication, division, square, or square root. Depending on the operation selected, the appropriate function is called to calculate the result and display the answer. The program uses PHP functions to define the calculations and return and display the output.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
44 views2 pages
Mariana Torres 4 Form
The document describes a calculator program created by Mariana Torres for a homework assignment. The program allows users to input two numbers and select an operation to perform - addition, subtraction, multiplication, division, square, or square root. Depending on the operation selected, the appropriate function is called to calculate the result and display the answer. The program uses PHP functions to define the calculations and return and display the output.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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>