kaveman50 Posted October 30, 2009 Share Posted October 30, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/179581-how-would-i-convert-this-into-code-using-an-if-statement/ Share on other sites More sharing options...
DavidAM Posted October 30, 2009 Share Posted October 30, 2009 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")'; } Quote Link to comment https://forums.phpfreaks.com/topic/179581-how-would-i-convert-this-into-code-using-an-if-statement/#findComment-947607 Share on other sites More sharing options...
kaveman50 Posted October 30, 2009 Author Share Posted October 30, 2009 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")'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/179581-how-would-i-convert-this-into-code-using-an-if-statement/#findComment-947696 Share on other sites More sharing options...
kaveman50 Posted October 30, 2009 Author Share Posted October 30, 2009 . Quote Link to comment https://forums.phpfreaks.com/topic/179581-how-would-i-convert-this-into-code-using-an-if-statement/#findComment-947715 Share on other sites More sharing options...
cags Posted October 30, 2009 Share Posted October 30, 2009 Syntax error is because all the if, elseif blocks are missing a closing bracket. They all have 3 opening brackets and 2 closing brackets. Quote Link to comment https://forums.phpfreaks.com/topic/179581-how-would-i-convert-this-into-code-using-an-if-statement/#findComment-947729 Share on other sites More sharing options...
kaveman50 Posted October 30, 2009 Author Share Posted October 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/179581-how-would-i-convert-this-into-code-using-an-if-statement/#findComment-947751 Share on other sites More sharing options...
kaveman50 Posted October 30, 2009 Author Share Posted October 30, 2009 Any suggestions guys? Quote Link to comment https://forums.phpfreaks.com/topic/179581-how-would-i-convert-this-into-code-using-an-if-statement/#findComment-947762 Share on other sites More sharing options...
DavidAM Posted October 30, 2009 Share Posted October 30, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/179581-how-would-i-convert-this-into-code-using-an-if-statement/#findComment-947780 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.