November 6, 200520 yr Howdy Ok, im needing some help. Does this code make anysense to anyone that knows Php? <html> <head><title>Ex 1</title></head> <? $retAge="70"; echo "The Retirement Age is $retAge"; $myAge="30"; echo "You are $myAge years old"; yearsLeft="$retAge-$myAge"; ?> <? echo "$retAge - $myAge=".($retAge-$myAge)."<br> echo "You Have $yearsLeft Years Left!"; </html> Ok, the idea is for a program to display how many years a user has left to retirement, (70 and 30 are pre defined) but i have no idea how to calculate vairables. Any help would be much appreciated!
November 6, 200520 yr Here ya go Wellsy... btw, I always use parenthesis on my echo statements, makes them a little easier to read. <html> <head><title>Ex 1</title></head> <? $retAge=70; echo ("The Retirement Age is $retAge.<br>"); $myAge=30; echo ("You are $myAge years old.<br><br>"); $yearsLeft=$retAge-$myAge; echo ("$retAge - $myAge = $yearsLeft<br>"); echo ("You Have $yearsLeft Years Left!"); ?> </html> The main reason it looks like your script wasn't running was because you had no $ in front of your yearsLeft variable. The only other thing that I really saw is that you were setting yearsLeft to a string because it was enclosed in quotes. yearsLeft="$retAge-$myAge"; This would make yearsLeft equal to "70-30" instead of the 40 that you want. Also, you do not need quotes when assigned the initial values to retAge and myAge. Their integers and syntacically should not have quotes. Quotes are reserved, generally speaking, for strings such as "Mary had a little lamb." The remainder of changes that I made were merely syntacical. Let me know if you have any questions about the changes that I made. Glad to help.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.