Go Back   Flash Flash Revolution > General Discussion > Critical Thinking > Homework & Help
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 07-12-2009, 02:50 AM   #1
Jintu
FFR Player
 
Join Date: Jul 2009
Posts: 15
Default [College -Computer Science 165] PHP Programming

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. I have set the value of "not done yet / excused" to -1......

Could someone help me on this, any help is greatly appreciated
Code:
<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>
Thanks,

Tony
Jintu is offline   Reply With Quote
Old 07-12-2009, 03:04 AM   #2
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: [College -Computer Science 165] PHP Programming

As in, if they skip 50% of the available marks and get 40% on what they did do, you'd recalculate it as an 80%?
Declare another variable. For every set of marks that they did do, add the total marks to this variable. At the end, divide the marks they got by the maximum marks they could have gotten and multiply by 100.

BTW, instead of writing out 'Your final grade...' 11 times, you should echo it once then in the if-elseif chain echo only the grade part, and echo a line break at the end. Code and data should be re-written out as little as necessary.
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png

Last edited by Patashu; 07-12-2009 at 03:06 AM..
Patashu is offline   Reply With Quote
Old 07-12-2009, 03:53 AM   #3
Jintu
FFR Player
 
Join Date: Jul 2009
Posts: 15
Default Re: [College -Computer Science 165] PHP Programming

Quote:
Originally Posted by Patashu View Post
As in, if they skip 50% of the available marks and get 40% on what they did do, you'd recalculate it as an 80%?
Declare another variable. For every set of marks that they did do, add the total marks to this variable. At the end, divide the marks they got by the maximum marks they could have gotten and multiply by 100.

BTW, instead of writing out 'Your final grade...' 11 times, you should echo it once then in the if-elseif chain echo only the grade part, and echo a line break at the end. Code and data should be re-written out as little as necessary.
I dun really get what you mean, for example, if they have not taken 40% of the available marks, the program has to calculate what marks they have got out of 60%, for e.g. 55 / 60 = 91.6%......
Jintu is offline   Reply With Quote
Old 07-12-2009, 04:08 AM   #4
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: [College -Computer Science 165] PHP Programming

Right. Thus, this solution:

Declare another variable. For every task that they did do, add the maximum marks of this task to this variable. At the end, divide the marks they got by this variable (the total maximum marks of all the tasks they did) and multiply by 100.
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png
Patashu is offline   Reply With Quote
Old 07-12-2009, 05:14 AM   #5
Jintu
FFR Player
 
Join Date: Jul 2009
Posts: 15
Default Re: [College -Computer Science 165] PHP Programming

Quote:
Originally Posted by Patashu View Post
Right. Thus, this solution:

Declare another variable. For every task that they did do, add the maximum marks of this task to this variable. At the end, divide the marks they got by this variable (the total maximum marks of all the tasks they did) and multiply by 100.
This is my new code I implemented, still it does not work, for it does acknowledge the fact that for the option, "not done yet / excused", it has to ignore the value..... Please help:
Code:
<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;
$total=0;
if ($_POST['Quiz1'] >= 0 && $_POST['Quiz1'] <= 100)
	$grade = $grade + $_POST['Quiz1'] * 0.05;
	$total = $total + 5;
if ($_POST['Mid-Term'] >= 0 && ($_POST['Mid-Term'] <= 100))
	$grade = $grade + $_POST['Mid-Term'] * 0.30;
	$total = $total + 30;
if ($_POST['Quiz2'] >= 0 && ($_POST['Quiz2'] <= 100))
	$grade = $grade + $_POST['Quiz2'] * 0.05;
	$total = $total + 5;
if ($_POST['AL1'] >= 0 && ($_POST['AL1'] <= 100))
	$grade = $grade + $_POST['AL1'] * 0.05;
	$total = $total + 5;
if ($_POST['AL2'] >= 0 && ($_POST['AL2'] <= 100))
	$grade = $grade + $_POST['AL2'] * 0.05;
	$total = $total + 5;
if ($_POST['Participation'] >= 0 && ($_POST['Participation'] <= 100))
	$grade = $grade + $_POST['Participation'] * 0.10;
	$total = $total + 10;
if ($_POST['Final'] >= 0 && ($_POST['Final'] <= 100))
	$grade = $grade + $_POST['Final'] * 0.40;
	$total = $total + 40;
$gradestatus = $grade / $total * 100

?>
<?php
echo "Grade Report: <br />";
echo "<br />";
?>
Your final grade percentage will be:  <?php echo $gradestatus . "%";
echo "<br />";
{
if ($gradestatus > 90.9)
	echo "Your final grade for the course will be: A+ <br />";
elseif ($gradestatus > 85.9)
	echo "Your final grade for the course will be: A  <br />";
elseif ($gradestatus > 79)
	echo "Your final grade for the course will be: A-  <br />";
elseif ($gradestatus > 76.9)
	echo "Your final grade for the course will be: B+  <br />";
elseif ($gradestatus >71.9)
	echo "Your final grade for the course will be: B  <br />";
elseif ($gradestatus > 69.9)
	echo "Your final grade for the course will be: B-  <br />";
elseif ($gradestatus > 65.9)
	echo "Your final grade for the course will be: C+  <br />";
elseif ($gradestatus > 59.9)
	echo "Your final grade for the course will be: C  <br />";
elseif ($gradestatus > 54.9)
	echo "Your final grade for the course will be: C-  <br />";
elseif ($gradestatus > 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>
Jintu is offline   Reply With Quote
Old 07-12-2009, 05:33 AM   #6
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: [College -Computer Science 165] PHP Programming

That seems like it would be fine, assuming the value for not done yet / excused is negative or greater than 100. If it's a string or something else you'd need to test for that as well.
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png
Patashu is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 04:50 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution