Jump to content

Simple Php Variables


Jonathan Harvey

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).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...