I’m making a php code to make the test media and at the end seem approved, failed or recovery but I don’t know what’s going wrong

Asked

Viewed 35 times

-2

 <?php 
$prova1 = 20;
$prova2 = 12;
$prova3 = 5;
  
  $media = ($prova1 + $prova2 + $prova3)/3;
echo "A média deu: $media";
if ($media >= 9,5)
{
echo "// Parabéns você foi aprovado";
}
elseif ($media > 8  && $media < 9,5)
{
echo "// Terá de ir a recuperação";
}
else ($media <= 8)
{
echo "// Você foi reprovado";
}
?>
  • In PHP the decimal separator is the point, so the number "nine and a half" is 9.5, nay 9,5. When executing the code appears the error stating this: "syntax error, Unexpected ',' ... on line 8"

  • Incidentally, else has no condition... he is the else...

  • And if the grades can be higher than 10, there’s no guarantee that the average will be 0 to 10.

  • Thanks for the help . By chance my friend told me about Isis but we do not remember that it was necessary point instead of comma

1 answer

0

we have 2 problems in this code the numbers in PHP we use . and not , to separate the decimals. the other problem is your LSE may not have value or change to elseif or remove the ().

<?php 

ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);

$prova1 = 20;
$prova2 = 12;
$prova3 = 5;
  
$media = ($prova1+$prova2+$prova3)/3;

 echo "A média deu: ".$media;
 if ($media >= 9.5)
{
     echo "// Parabéns você foi aprovado";
 }
elseif ($media > 8  && $media < 9.5)
{
    echo "// Terá de ir a recuperação";
}
elseif ($media <= 8)
{
    echo "// Você foi reprovado";
}

?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.