Server IP : 172.16.15.8 / Your IP : 3.15.214.185 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/thchang/cs480/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php session_start(); ?> <!-- Title: assignment4b3.php Author: Tyler Chang Instructor: John Wang Due: 3/3/2013 Goal: Add modulus and power functions to calculator app --> <FONT color=blue size=4> <?php // get op and numbers from last page $op = $_POST['op']; $num1 = $_SESSION['num1']; $num2 = $_SESSION['num2']; // display print "Num1 is $num1<BR>"; print "Num2 is $num2<BR>"; print "The opperator is $op<p>"; if($op == "add") // add the numbers { $ans = $num1 + $num2; print "$num1 + $num2 = $ans"; } else if($op == "sub") // subtract the numbers { $ans = $num1 - $num2; print "$num1 - $num2 = $ans"; } else if($op == "mul") // multiply the numbers { $ans = $num1 * $num2; print "$num1 * $num2 = $ans"; } else if($op == "div") // divide the numbers { $ans = $num1 / $num2; print "$num1 / $num2 = $ans"; } else if($op == "mod") // find remainder { $ans = $num1 % $num2; print "$num1 % $num2 = $ans"; } else if($op == "pow") // find num1 to num2 power { $ans = 1; if($num2 < 0) // raised to a negative power for($i=$num2;$i<0;$i++) $ans = $ans / ($num1); else // raised to a positive power for($i=0;$i<$num2;$i++) $ans = $ans * $num1; print "$num1 ^ $num2 = $ans"; } ?> <p> <A HREF=index.html> Return Home. </A> </FONT>