vendredi 30 novembre 2018

How can I calculate min, max and average value in a while loop?

I have the following code:

<?php
echo "<p>Exercise 5:</p>";

echo "Numbers: ";

$random = 0;

while ($random < 10) {
    $rand = rand(2, 80);
    echo "$rand";

    $random = $random + 1;

    if ($random < 10) {
     echo ", ";
    };
}

echo "<br><br>Min value: <br>";
echo "Max value: <br>";
echo "Average value: <br>";

?>

How can I calculate the min, max and average value of the 10 numbers?

$min = min($rand) doesn't work...
$max = max($rand) doesn't work either...




Aucun commentaire:

Enregistrer un commentaire