Advertisement
Shailrshah

Using Function to Calculate Average

Apr 29th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. form.html
  2. <html>
  3. <head>
  4.     <title>A form</title>
  5. </head>
  6. <body>
  7.     <form method = "get" action = "test.php">
  8.         WP:     <input type = "text" name = "wp" />
  9.         CN:     <input type = "text" name = "cn" />
  10.         COA:    <input type = "text" name = "coa" />
  11.         <input type = "submit" value ="Find average"/>
  12.     </form>
  13. </body>
  14. </html>
  15.  
  16. test.php
  17. <html>
  18. <body>
  19.     <?php
  20.         function calcAvg($wp, $cn, $coa){
  21.             return ($wp+$cn+$coa)/3;
  22.         }
  23.         $wp = $_GET["wp"];
  24.         $cn = $_GET["cn"];
  25.         $coa = $_GET["coa"];
  26.         $average = calcAvg($wp, $cn, $coa);
  27.         echo "The average is ". $average;
  28.     ?>
  29. </body>
  30. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement