Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,930 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,832 people online right now. Registration is fast and FREE... Join Now!




trouble with php average grade and letter grade

 
Reply to this topicStart new topic

trouble with php average grade and letter grade

chica1977
26 Mar, 2008 - 06:45 PM
Post #1

New D.I.C Head
*

Joined: 26 Mar, 2008
Posts: 2

I am having trouble getting my code to display right. I put everything in on the html and hit submit and the php page comes up without calculating. I am having trouble understanding what I'm doing wrong.

CODE

<html>
<head>
<title> Grade Book</title>
</head>
<body>

<?php
$fname=$_REQUEST["fname"];
$lname=$_REQUEST["lname"];
$test1=$_REQUEST["test1"];
$test2=$_REQUEST["test2"];
$test3=$_REQUEST["test3"];


//test information
$avg = average($test1, $test2, $test3);
$lg = lettergrade($avg);
fname();
lname();
$test1 = test1($avg);
$test2 = test2($avg);
$test3 = test3($avg);
avg();


function fname()
{print "First Name:";
print $fname;
print "<br>";
print "<br>";
}

function lname()
{print "Last Name:";
print "<br>";
print "<br>";
}

function test1()
{print "Test 1";
print "<br>";
print "<br>";
}

function test2()
{print "Test 2";
print "<br>";
print "<br>";
}

function test3()
{print "Test 3";
print "<br>";
print "<br>";
}

function avg()
{print "Average Grade";
print "<br>";
print "<br>";
}

function average($test1,$test2,$test3)
{
$avg = ($test1 + $test2 + $test3) / 3;
return $avg;
}

function lettergrade($avg)
{
    if ($avg >= 90)
    $lettergrade = "A";

    if ($avg >= 80 && $avg <= 89)
    $lettergrade = "B";

    if ($avg >= 70 && $avg <= 79)
    $lettergrade = "C";

    if ($avg >= 60 && $avg <= 69)
    $lettergrade = "D";

    if ($avg >= 50 && $avg <= 59)
    $lettergrade = "F";

    
return $lettergrade;
}






?>

</body>
</html>

User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Trouble With Php Average Grade And Letter Grade
26 Mar, 2008 - 07:13 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,495



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(chica1977 @ 26 Mar, 2008 - 07:45 PM) *

I am having trouble getting my code to display right. I put everything in on the html and hit submit and the php page comes up without calculating. I am having trouble understanding what I'm doing wrong.

CODE

$fname=$_REQUEST["fname"];
$lname=$_REQUEST["lname"];
$test1=$_REQUEST["test1"];
$test2=$_REQUEST["test2"];
$test3=$_REQUEST["test3"];


Where are these values being sent to the php page? It's requesting information, but it isn't actually getting the values from anywhere. To troubleshoot it, try putting them into the URL (as get values) or just manually set them & see if it will process them that way. If that does work for you, then you need to setup a form w/submit button.
User is online!Profile CardPM
+Quote Post

pertheusual
RE: Trouble With Php Average Grade And Letter Grade
26 Mar, 2008 - 07:20 PM
Post #3

D.I.C Head
**

Joined: 26 Jan, 2008
Posts: 231



Thanked: 3 times
My Contributions
What are you using to submit the values to the php? Are you just typing them in the address bar?(Covered by no2pencil)

You might want to consider using "$_GET" instead of $_REQUEST.

Anyway, the main thing I see is that you don't actually have it printing "$avg", "$lname" or "$lg" anywhere. You also pass $avg to the test functions for some reason, when those functions have no inputs.

Your fname function also won't work because $fname is not global. Put "global $fname;" in your fname function.

Really though, you should just have a few print statements in the main section. You only really need the functions to calculate the average and letter grade.

Per
User is offlineProfile CardPM
+Quote Post

chica1977
RE: Trouble With Php Average Grade And Letter Grade
26 Mar, 2008 - 08:06 PM
Post #4

New D.I.C Head
*

Joined: 26 Mar, 2008
Posts: 2

Thank you so much. My teacher has gotten me so confused I don't know what I'm doing anymore.


QUOTE(pertheusual @ 26 Mar, 2008 - 08:20 PM) *

What are you using to submit the values to the php? Are you just typing them in the address bar?(Covered by no2pencil)

You might want to consider using "$_GET" instead of $_REQUEST.

Anyway, the main thing I see is that you don't actually have it printing "$avg", "$lname" or "$lg" anywhere. You also pass $avg to the test functions for some reason, when those functions have no inputs.

Your fname function also won't work because $fname is not global. Put "global $fname;" in your fname function.

Really though, you should just have a few print statements in the main section. You only really need the functions to calculate the average and letter grade.

Per


User is offlineProfile CardPM
+Quote Post

pertheusual
RE: Trouble With Php Average Grade And Letter Grade
26 Mar, 2008 - 08:15 PM
Post #5

D.I.C Head
**

Joined: 26 Jan, 2008
Posts: 231



Thanked: 3 times
My Contributions
No problem. Teachers tend to do that, even if they do try their best. We are more than happy to help.

Per
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 10:36PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month