Jump to content

Simple Php Variables


Jonathan Harvey
 Share

Recommended Posts

hi, I know this is very simple, but I'm a begginer at php. I'm trying to convert fahrenheit to celsius then have the output from -50, to 50 degrees in both displayed. This is the Code:

$f = -50;$c = $f (-32 *5 / 9);

can someone please tell me why the assignment to the variable $c won't work? Thanks

Link to comment
Share on other sites

You're missing an operator after $f, you need a multiplication operator there.$c = $f * (-32 *5 / 9);
why do I need that extra * ? because what I need to do is minus 32, times by 5, and divide by 9, so won't that mess up the value? sorry, like I said I'm a begginer
Link to comment
Share on other sites

Yes, that was a mistake. The operation is as you describe, but you've bracketed the wrong area. You want the subtraction to have higher priority than the multiplication and division so it's:

<?php$fahrenheit = -50;$celsuis = ($fahrenheit - 32) * (5/9);?>

The last brackets there aren't needed, but make things a little bit clearer. You can keep using $c and $f if you like, but I'd advocate typing a little bit more for the obvious descriptive qualities of a longer variable identifier (name).

Edited by AElliott
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...