Jump to content

PHP Parse Error

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
crd06c

crd06c

    Newbie

  • Members
  • Pip
  • 1 posts
I dont know where im going wrong.

Can anyone help? This is my first time programming with PHP.

<body>
<div id="container">
  <div id="mainContent">
    <h1> College Progress Calculator</h1>
<?php

$total_credits = 120;
$credits_earned = $_POST["credits_earned"];
$name = $_POST["name"];
$credits_remaining = $total_credits - $credits_earned;
$percent_gone = $credits_remaining / $total_credits;

echo "<p>Hi " . $name . "!</p>";
echo "<p> Wow! You've already completed ". $credits_earned . " hours!</p>";
echo "<p> Only " . credits_remaining . " to go!</p>";
echo "<p> You have completed " . $percent_gone . " of your undergraduate degree.</p>";

if ($percent_gone < .3){
	echo "<p>That Makes you a Freshman!</p>";
}
elseif ($percent_gone < .6){
	echo "<p>That makes you a Sophomore!</p>";
}
elseif ($percent_gone < .9 { 
	echo "<p>That makes you a Junior!</p>";
}
elseif ($percent_gone = 1.0 { 
	echo "<p>You are ready to GRADUATE!!!</p>";
}

?>
<p> </p>
</div>
</div>
</body>
</html>

Im trying to create a calculator.
Its for my programming course.

Edited by Jordan, 07 July 2009 - 11:00 AM.
Added code tags


#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Hey crd06c, welcome to the forum! I've added code tags to your post so that it is easier to see. If you post code again, please do the same. :)

If you look at lines 24 and 27 you'll see that you forgot your ending ) on the condition. You also are making an assignment statement on line 27 instead of testing the condition. Use double ==

elseif ($percent_gone == 1.0) { 

On line 15 you are missing the dollar sign from your variable credits_remaining. That should fix it up.

#3
sdavis2702

sdavis2702

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
Also, shouldn't line 11 be...

$percent_gone = $credits_earned / $total_credits;

Instead of...

$percent_gone = $credits_remaining / $total_credits;

...to show what has been completed (percent_gone)? I copied and pasted this snippet and played around with it on my own computer and found that the calculator was giving more of an inversely proportional reading of credits completed to class year ratio. What I mean is, those who had earn more credits were freshmen and sophomores and those who earn less credits were juniors and seniors.

Am I correct or still confused about how everything works? lol
My Name is Sean and I like codes and stuff...
NoobJunction.com | SuccessOnMyMind.com | ArmedForcesCarClub.com

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Sounds logically correct to me! (your correction, that is) :)