Jintu Posted July 11, 2009 Share Posted July 11, 2009 Below is the code I have used for my php program which is linked to a html file, this program calculates grades, everything is correct, except for the fact that If the user selects the option "not done yet / excused", it must be able to calculate without taking the % of the whatever quzi, mid-term, etc that that they missed, ie if they have only taken 50% of the available marks in the course, it must be able to just calculate that. Could someone help me on this, any help is greatly appreciated Thanks, Tony <html> <head> <link rel="stylesheet" type="text/css" href="2.css" /> <title>Grade Calculator</title> </head> <?php ?> <body> <?php $grade = 0; if ($_POST['Quiz1'] >= 0 && $_POST['Quiz1'] <= 100) $grade = $grade + $_POST['Quiz1'] * 0.05; else $grade = $grade + 5; if ($_POST['Mid-Term'] >= 0 && ($_POST['Mid-Term'] <= 100)) $grade = $grade + $_POST['Mid-Term'] * 0.30; else $grade = $grade + 30; if ($_POST['Quiz2'] >= 0 && ($_POST['Quiz2'] <= 100)) $grade = $grade + $_POST['Quiz2'] * 0.05; else $grade = $grade + 5; if ($_POST['AL1'] >= 0 && ($_POST['AL1'] <= 100)) $grade = $grade + $_POST['AL1'] * 0.05; else $grade = $grade + 5; if ($_POST['AL2'] >= 0 && ($_POST['AL2'] <= 100)) $grade = $grade + $_POST['AL2'] * 0.05; else $grade = $grade + 5; if ($_POST['Participation'] >= 0 && ($_POST['Participation'] <= 100)) $grade = $grade + $_POST['Participation'] * 0.10; else $grade = $grade + 10; if ($_POST['Final'] >= 0 && ($_POST['Final'] <= 100)) $grade = $grade + $_POST['Final'] * 0.40; else $grade = $grade + 40; ?> <?php echo "Grade Report: <br />"; echo "<br />"; ?> Your final grade percentage will be: <?php echo $grade . "%"; echo "<br />"; { if ($grade > 90.9) echo "Your final grade for the course will be: A+ <br />"; elseif ($grade > 85.9) echo "Your final grade for the course will be: A <br />"; elseif ($grade > 79) echo "Your final grade for the course will be: A- <br />"; elseif ($grade > 76.9) echo "Your final grade for the course will be: B+ <br />"; elseif ($grade >71.9) echo "Your final grade for the course will be: B <br />"; elseif ($grade > 69.9) echo "Your final grade for the course will be: B- <br />"; elseif ($grade > 65.9) echo "Your final grade for the course will be: C+ <br />"; elseif ($grade > 59.9) echo "Your final grade for the course will be: C <br />"; elseif ($grade > 54.9) echo "Your final grade for the course will be: C- <br />"; elseif ($grade > 49.9) echo "Your final grade for the course will be: P <br />"; else echo "Your final grade for the course will be: F <br />"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/165587-creating-a-grade-calculator-using-php-and-html/ Share on other sites More sharing options...
genericnumber1 Posted July 11, 2009 Share Posted July 11, 2009 You just need to multiply $grade by 100/maxPossibleMarks. Figure out how to calculate the maximum number of possible marks thus far in the semester and it will be trivial to implement. Link to comment https://forums.phpfreaks.com/topic/165587-creating-a-grade-calculator-using-php-and-html/#findComment-873726 Share on other sites More sharing options...
Jintu Posted July 11, 2009 Author Share Posted July 11, 2009 I dun get you mean, so far in the course they would have done everything less the al2 and final, which have a combined value of 45%, so how could I implement this, please help.... Tony Link to comment https://forums.phpfreaks.com/topic/165587-creating-a-grade-calculator-using-php-and-html/#findComment-873761 Share on other sites More sharing options...
genericnumber1 Posted July 11, 2009 Share Posted July 11, 2009 Then, since the maximum number of marks thus far in the semester is 55 (because 45 are, as of yet, unattainable) you simply multiply $grade by 100/55 to get the current grade excluding al2 and final. I'm explaining the approach, not the code to back it up. Link to comment https://forums.phpfreaks.com/topic/165587-creating-a-grade-calculator-using-php-and-html/#findComment-873765 Share on other sites More sharing options...
Jintu Posted July 11, 2009 Author Share Posted July 11, 2009 Icic, thank you. So if I want to learn about the code to implement the function, I have to post it in the other section right...... Thanks Tony Link to comment https://forums.phpfreaks.com/topic/165587-creating-a-grade-calculator-using-php-and-html/#findComment-873773 Share on other sites More sharing options...
genericnumber1 Posted July 11, 2009 Share Posted July 11, 2009 No, no, people will give you code help here, but I'm often more of the philosophy of not writing code for people if I think they're capable of writing it themselves. What you have written as far as the current existing code goes is all you need to implement the feature you described. if/then/else, form handling, and the basic math operators are all that are needed, and since you wrote that code above I'm confident you can add the feature you described if you give it enough thought. Link to comment https://forums.phpfreaks.com/topic/165587-creating-a-grade-calculator-using-php-and-html/#findComment-873787 Share on other sites More sharing options...
Jintu Posted July 11, 2009 Author Share Posted July 11, 2009 No, no, people will give you code help here, but I'm often more of the philosophy of not writing code for people if I think they're capable of writing it themselves. What you have written as far as the current existing code goes is all you need to implement the feature you described. if/then/else, form handling, and the basic math operators are all that are needed, and since you wrote that code above I'm confident you can add the feature you described if you give it enough thought. Hello, this is the code I have implemented, however I am not sure if this is correct or not although it work because it might work wrongly if the user selects the other fields, pls advise.... <html> <head> <link rel="stylesheet" type="text/css" href="http://96.48.39.33/student13/bala2.css" /> <title>Grade Calculator</title> </head> <body> <?php $grade = 0; if ($_POST['Quiz1'] >= 0 && $_POST['Quiz1'] <= 100) $grade = $grade + $_POST['Quiz1'] * 0.05; else $grade = $grade + 5; if ($_POST['Mid-Term'] >= 0 && ($_POST['Mid-Term'] <= 100)) $grade = $grade + $_POST['Mid-Term'] * 0.30; else $grade = $grade + 30; if ($_POST['Quiz2'] >= 0 && ($_POST['Quiz2'] <= 100)) $grade = $grade + $_POST['Quiz2'] * 0.05; else $grade = $grade + 5; if ($_POST['AL1'] >= 0 && ($_POST['AL1'] <= 100)) $grade = $grade + $_POST['AL1'] * 0.05; else $grade = $grade + 5; if ($_POST['AL2'] >= 0 && ($_POST['AL2'] <= 100)) $grade = $grade + $_POST['AL2'] * 0.05; else $grade = $grade + 5; if ($_POST['Participation'] >= 0 && ($_POST['Participation'] <= 100)) $grade = $grade + $_POST['Participation'] * 0.10; else $grade = $grade + 10; if ($_POST['Final'] >= 0 && ($_POST['Final'] <= 100)) $grade = $grade + $_POST['Final'] * 0.40; else $grade = $grade + 40; $currentgrade = $grade * 100 / 55 ?> <?php echo "Grade Report: <br />"; echo "<br />"; ?> Your final grade percentage will be: <?php echo $currentgrade . "%"; echo "<br />"; { if ($currentgrade > 90.9) echo "Your final grade for the course will be: A+ <br />"; elseif ($currentgrade > 85.9) echo "Your final grade for the course will be: A <br />"; elseif ($currentgrade > 79) echo "Your final grade for the course will be: A- <br />"; elseif ($currentgrade > 76.9) echo "Your final grade for the course will be: B+ <br />"; elseif ($currentgrade >71.9) echo "Your final grade for the course will be: B <br />"; elseif ($currentgrade > 69.9) echo "Your final grade for the course will be: B- <br />"; elseif ($currentgrade > 65.9) echo "Your final grade for the course will be: C+ <br />"; elseif ($currentgrade > 59.9) echo "Your final grade for the course will be: C <br />"; elseif ($currentgrade > 54.9) echo "Your final grade for the course will be: C- <br />"; elseif ($currentgrade > 49.9) echo "Your final grade for the course will be: P <br />"; else echo "Your final grade for the course will be: F <br />"; } ?> </body> </html> Thanks, Tony Link to comment https://forums.phpfreaks.com/topic/165587-creating-a-grade-calculator-using-php-and-html/#findComment-873795 Share on other sites More sharing options...
genericnumber1 Posted July 12, 2009 Share Posted July 12, 2009 Well... 1) First ask yourself why you're adding the max amount to the grade if the grades are out of the range 0-100. (I'm not sure why you are...) 2) You might then ask how you would signify whether or not a grade is to be counted on the form's input. (Has it occurred yet? Do you mark the grade as -1 to signify it isn't to be counted? A checkbox that says "don't count this" perhaps?) 3) You can then consider how you would keep a count of the total number of possible points excluding those grades that aren't to be counted in the average (see 2). At that point you can get the grade by doing grade*(100/ValueFromPoint3Above). Link to comment https://forums.phpfreaks.com/topic/165587-creating-a-grade-calculator-using-php-and-html/#findComment-873850 Share on other sites More sharing options...
Jintu Posted July 12, 2009 Author Share Posted July 12, 2009 Hello, I dun quite understand the 1st Point, well i tried the 2nd part, it seems to calculate ok, expect the fact that I used my own grades and in my teacher's gradebook it shows as 91.5% whereas in mine it calculates at 96.45%, this is excluding AL2 and Final, please advise, my code is reflected below: <html> <head> <link rel="stylesheet" type="text/css" href="http://96.48.39.33/student13/bala2.css" /> <title>Grade Calculator</title> </head> <body> <?php $grade=0; if ($_POST['Quiz1'] >= 0 && $_POST['Quiz1'] <= 100) $grade = $grade + $_POST['Quiz1'] * 0.05; else $grade = $grade + 5; if ($_POST['Mid-Term'] >= 0 && ($_POST['Mid-Term'] <= 100)) $grade = $grade + $_POST['Mid-Term'] * 0.30; else $grade = $grade + 30; if ($_POST['Quiz2'] >= 0 && ($_POST['Quiz2'] <= 100)) $grade = $grade + $_POST['Quiz2'] * 0.05; else $grade = $grade + 5; if ($_POST['AL1'] >= 0 && ($_POST['AL1'] <= 100)) $grade = $grade + $_POST['AL1'] * 0.05; else $grade = $grade + 5; if ($_POST['AL2'] >= 0 && ($_POST['AL2'] <= 100)) $grade = $grade + $_POST['AL2'] * 0.05; else $grade = $grade + 5; if ($_POST['Participation'] >= 0 && ($_POST['Participation'] <= 100)) $grade = $grade + $_POST['Participation'] * 0.10; else $grade = $grade + 10; if ($_POST['Final'] >= 0 && ($_POST['Final'] <= 100)) $grade = $grade + $_POST['Final'] * 0.40; else $grade = $grade + 40; ?> <?php echo "Grade Report: <br />"; echo "<br />"; ?> Your final grade percentage will be: <?php echo $grade . "%"; echo "<br />"; { if ($grade > 90.9) echo "Your final grade for the course will be: A+ <br />"; elseif ($grade > 85.9) echo "Your final grade for the course will be: A <br />"; elseif ($grade > 79) echo "Your final grade for the course will be: A- <br />"; elseif ($grade > 76.9) echo "Your final grade for the course will be: B+ <br />"; elseif ($grade >71.9) echo "Your final grade for the course will be: B <br />"; elseif ($grade > 69.9) echo "Your final grade for the course will be: B- <br />"; elseif ($grade > 65.9) echo "Your final grade for the course will be: C+ <br />"; elseif ($grade > 59.9) echo "Your final grade for the course will be: C <br />"; elseif ($grade > 54.9) echo "Your final grade for the course will be: C- <br />"; elseif ($grade > 49.9) echo "Your final grade for the course will be: P <br />"; else echo "Your final grade for the course will be: F <br />"; } ?> </body> </html> Thank you... Tony Link to comment https://forums.phpfreaks.com/topic/165587-creating-a-grade-calculator-using-php-and-html/#findComment-873872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.