Jump to content

How would I convert this into code using an if statement?


kaveman50

Recommended Posts

ES equals exam score m equals $mean s equals $total.  I already coded my mean and total so I'm not going to post my code unless it is necessary.  I want to know how to get this into code form using if statements, and also how to echo it.

 

ES > or equal to m + 1.5s (This will tell what grades are an A)

m + .5s <or equal to ES < m + 1.5s (This will tell what grades are an B)

m - .5s < or equal to ES < m + .5s (This will tell what grades are an C)

m - 1.5s < or equal to ES < m - .5s (This will tell what grades are an D)

ES , m - 1.5s (This will tell what grades are an F)

if ($ES >= ($mean + (1.5 * $total)) {
  echo 'A';
} elseif ($ES >= ($mean + (.5 * $total)) {
  echo 'B';
} elseif ($ES >= ($mean - (.5 * $total)) {
  echo 'C';
} elseif ($ES >= ($mean - (1.5 * $total)) {
  echo 'D';
} else {
  echo 'F (what ever happened to "E")';
}

it says Parse error: syntax error, unexpected '{' in /Applications/XAMPP/xamppfiles/htdocs/webalizer/Midterm.php on line 31

 

also where's the .5? Here's my code.

 

<?php
//mean
$numbers = array(59,60,65,75,56,90,66,62,98,72,95,71,63,77,65,77,65,50,85,62); 
$n = sizeof($numbers);

$mean = round(array_sum($numbers), 1) / $n;  
//(xsub1-m)^2+(xsub2-m)^2+(xsub3-m)^2+...+(xsubn-m)^2 all divided by n-1
$total = 0;
foreach($numbers as $num){
$total += pow($num-$mean,2);
}
$total = sqrt($total / ($n-1));
echo "Mean: ",$mean;
echo "<br>";
echo "Standard Deviation: ",round($total,5);










if($exam_score >= $mean + round($total,5))
{
     $grade = 'A';

}
if ($ES >= ($mean + (1.5 * $total)) {
  echo 'A';
} elseif ($ES >= ($mean + (.5 * $total)) {
  echo 'B';
} elseif ($ES >= ($mean - (.5 * $total)) {
  echo 'C';
} elseif ($ES >= ($mean - (1.5 * $total)) {
  echo 'D';
} else {
  echo 'F (what ever happened to "E")';
}


?>

if ($ES >= ($mean + (1.5 * $total))) {
  echo 'A';
} elseif ($ES >= ($mean + (.5 * $total))) {
  echo 'B';
} elseif ($ES >= ($mean - (.5 * $total))) {
  echo 'C';
} elseif ($ES >= ($mean - (1.5 * $total))) {
  echo 'D';
} else {
  echo 'F';
}

 

 

Alright, I changed it to that, but it only outputs the letter F.

1) Sorry about the missing parenthesis, I really have to learn to count.

 

2) Since you did not state the varaible name for the exam score, I just picked up a spare one laying on my desk, it was called $ES.  Now that you have posted some code, I see that yours is called $exam_score, so you need to change all those $ES to $exam_score.

 

also where's the .5?

3) Where is what .5? There's one in there for the B and one for the C.  If you are asking about the calculation for the F, you don't really need it because if it is not an A, B, C, or D then it has to be an F; right?

 

4) Your original post simply asked how to make the IF statement for the different grade rules.  So, that's what I wrote.  You said you already had some code so I just put 'echo' in there where the grade would be.  I assumed you would change the 'echo' to whatever it needed to be to fit with the rest of your code (which we could not see).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.