0
Make an application to read 6 values. Calculate and display:
to) The typed sequence;
b) the average of them;
c) values above the average.
I can print the sequence, I can add it up, but it’s not hitting the media, and I’m not getting to do it consistently!
My code so far
<?php
$valores = array();
$media = 0;
$soma = 0;
for ($i = 0; $i < 6; $i++) {
printf("Digite um valor:");
fscanf(STDIN, "%d \n", $valores[$i]);
}
for ($i = 0; $i < 6; $i++) {
printf("$valores[$i] \n");
if ($media < $valores[$i]) {
$soma = $soma + $valores[$i];
$media = $soma / 6;
if ($valores[$i] >= $media) {
$acimaM = $valores[$i];
printf("E os valores acima da media sao " . $acimaM[$i]);
}
}
}
printf("A media e " . $media . "\n");
What is your question? What have you tried?
– Erlon Charles
I can print the sequence, I can add it, but it’s not hitting the media, and I’m not getting to do it consistently!
– Wiuver Ribeiro
<?php $values = array(); $media = 0; $soma = 0; for($i=0;$i<6;$i++){ printf("Type a value:"); fscanf(STDIN,"%d n", $values[$i]); } for($i=0;$i<6;$i++){&#printf("$values[$i]) if($media < values[$$i]){ $sum = $sum + $values[$i]; $media = $sum/6; if($values[$i]>= $media){ $acimaM = $values[$i]; printf("And the above-average values are ". $acimaM[$i]); } } } printf("The media and ". $media." n");
– Wiuver Ribeiro