Reputation: 41
I'm doing something probably very silly, wondering if I could get anyone to point out what I'm doing wrong. Teaching myself php, and in doing so I'm trying to make a wage calculator. It gives me these results:
Your results:
29 years old earning
$205per day working
$5days a week at a
Your total earned money at age 65 is $0.
While your yearly income is
49200
The total earned money figure is not correct though, obviously. 0 isn't right.
Here's the full code
<?php
//get the values from the $_POST array
$age = $_POST['age'];
$days = $_POST['days'];
$pay = $_POST['pay'];
//calculate the total:
$howold = 65 - $age;
$retireageincome = $yearlyincome * $howold;
$yearlyincome = $pay * $days * 4 * 12;
//print out results
print "<p>Your results:<br>
<span class=\"number\">$age</span> years old earning <br>
$<span class=\"number\">$pay</span>per day working <br>
$<span class=\"number\">$days</span>days a week at a<br>
Your total earned money at age 65 is $<span class=\"number
\">$retireageincome</span>.<br>
While your yearly income is <br>
<span class=\"number\">$yearlyincome</span> </p>";
?>
</body>
</html>
Upvotes: 0
Views: 35
Reputation: 8101
You are trying to use $yearlyincome
before the value of $yearlyincome
is known.
Order of commands matters. Move the
$yearlyincome = $pay * $days * 4 * 12;
to be before the line where $yearlyincome
is used and you should see a non-0 value.
Upvotes: 1