I dont know where im going wrong.
Can anyone help? This is my first time programming with PHP.
Im trying to create a calculator.Code:<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>
Its for my programming course.
Last edited by Jordan; 07-07-2009 at 12:00 PM. Reason: Added code tags
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 ==
On line 15 you are missing the dollar sign from your variable credits_remaining. That should fix it up.Code:elseif ($percent_gone == 1.0) {
Also, shouldn't line 11 be...
Instead of...Code:$percent_gone = $credits_earned / $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.Code:$percent_gone = $credits_remaining / $total_credits;
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
Sounds logically correct to me! (your correction, that is)![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks