Jump to content

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.