Jonathan Harvey Posted August 4, 2009 Share Posted August 4, 2009 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 More sharing options...
justsomeguy Posted August 4, 2009 Share Posted August 4, 2009 You're missing an operator after $f, you need a multiplication operator there.$c = $f * (-32 *5 / 9); Link to comment Share on other sites More sharing options...
Jonathan Harvey Posted August 4, 2009 Author Share Posted August 4, 2009 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 More sharing options...
AElliott Posted August 4, 2009 Share Posted August 4, 2009 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 More sharing options...
justsomeguy Posted August 4, 2009 Share Posted August 4, 2009 Sorry, I posted that and re-read it and tried to correct but my post but the forum was timing out. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.