4 Replies - 2243 Views - Last Post: 26 March 2008 - 09:15 PM Rate Topic: -----

#1 chica1977  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-March 08

trouble with php average grade and letter grade

Post icon  Posted 26 March 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.

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



Is This A Good Question/Topic? 0
  • +

Replies To: trouble with php average grade and letter grade

#2 no2pencil  Icon User is online

  • Head MFIC
  • member icon

Reputation: 5072
  • View blog
  • Posts: 26,465
  • Joined: 10-May 07

Re: trouble with php average grade and letter grade

Posted 26 March 2008 - 08:13 PM

View Postchica1977, on 26 Mar, 2008 - 07:45 PM, said:

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.

$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.
Was This Post Helpful? 0
  • +
  • -

#3 pertheusual  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 245
  • Joined: 26-January 08

Re: trouble with php average grade and letter grade

Posted 26 March 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
Was This Post Helpful? 0
  • +
  • -

#4 chica1977  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-March 08

Re: trouble with php average grade and letter grade

Posted 26 March 2008 - 09:06 PM

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


View Postpertheusual, on 26 Mar, 2008 - 08:20 PM, said:

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

Was This Post Helpful? 0
  • +
  • -

#5 pertheusual  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 245
  • Joined: 26-January 08

Re: trouble with php average grade and letter grade

Posted 26 March 2008 - 09:15 PM

No problem. Teachers tend to do that, even if they do try their best. We are more than happy to help.

Per
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1