What's new

Help .

PHP:
<?php
/*Create a function that will calculate the average temperature of Seoul, South Korea.
Seoul: 0.6, 3.3, 9.4, 16.7, 22.2, 26.1, 27.8, 28.9, 25.0, 18.9, 10.6, 3.3

Display the final average temperature of Seoul.
Include comments in your script to explain what you have done.
*/

//FUNCTION

function ave(int $x, int $y) {
    $z = $x / $y;
    return $z;
  }

//END OF FUNCTION

$temp = array(0.6, 3.3, 9.4, 16.7, 22.2, 26.1, 27.8, 28.9, 25.0, 18.9, 10.6, 3.3); //Value in array form
$total =  array_sum($temp); //To sum all the temperature of Seoul
$no = count($temp); //To get the no. of array value

echo  "Final Average of Seoul is ". ave($total, $no); //display the final average

?>
 

Similar threads

Back
Top