NewbiePHP22 Posted October 6, 2009 Share Posted October 6, 2009 I'm new here, and to PHP as well. I would like to know two things: How to setup temp. conversion, Fahrenheit to Celsius, so that 0 through 100 F is echo'd with the Celsius conversion echo'd beside it. And, I would like to know how make a script that checks if the combined length of any two sides of a triangle is greater than the length of the third side. Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/176630-solved-temperature-conversion-and-sides-of-a-triangle/ Share on other sites More sharing options...
NewbiePHP22 Posted October 6, 2009 Author Share Posted October 6, 2009 <?php $fahrenheit = 0; while ($fahrenheit < 100){ $F[] = $fahrenheit; ++$fahrenheit; foreach ($F as $Celsius){ $Celsius = (($fahrenheit - 32) / 1.; echo "$fahrenheit F ", "<--> ", round($Celsius, 1), " C<br />"; } } ?> This is what it is showing with the code I currently have: 1 F <--> -17.2 C 2 F <--> -16.7 C 2 F <--> -16.7 C 3 F <--> -16.1 C 3 F <--> -16.1 C 3 F <--> -16.1 C However, I need it to show like this: 0 F <--> -17.7 C 1 F <--> -17.2 C 2 F <--> -16.7 C 3 F <--> -16.1 C 4 F <--> -15.6 C 5 F <--> -15 C Link to comment https://forums.phpfreaks.com/topic/176630-solved-temperature-conversion-and-sides-of-a-triangle/#findComment-931224 Share on other sites More sharing options...
Whitts Posted October 6, 2009 Share Posted October 6, 2009 <?php for ($fahrenheit = 0; $fahrenheit <= 100; $fahrenheit++) { $celsius = (($fahrenheit - 32) / 1.; echo $fahrenheit . " F <--> " . round($celsius, 1) . " C<br />"; } ?> If you are unfamiliar with FOR loops, refer to this page. Regarding your triangle problem, I'm pretty sure that any two sides of a triangle will always be longer than the third side (unless I've misunderstood your question). Link to comment https://forums.phpfreaks.com/topic/176630-solved-temperature-conversion-and-sides-of-a-triangle/#findComment-931258 Share on other sites More sharing options...
NewbiePHP22 Posted October 6, 2009 Author Share Posted October 6, 2009 <?php for ($fahrenheit = 0; $fahrenheit <= 100; $fahrenheit++) { $celsius = (($fahrenheit - 32) / 1.; echo $fahrenheit . " F <--> " . round($celsius, 1) . " C<br />"; } ?> If you are unfamiliar with FOR loops, refer to this page. Regarding your triangle problem, I'm pretty sure that any two sides of a triangle will always be longer than the third side (unless I've misunderstood your question). Yes, it will be. lol I just don't understand how to put that into PHP so that it checks to make sure that is always the case. And, if it's not, then it returns an error. Ideally, I would have a html form with three text-entry boxes that would do a $_GET to refer back to the php so that it checks if the values one enters would make a triangle. Sorry for not explaining that better. Link to comment https://forums.phpfreaks.com/topic/176630-solved-temperature-conversion-and-sides-of-a-triangle/#findComment-931260 Share on other sites More sharing options...
Whitts Posted October 6, 2009 Share Posted October 6, 2009 Something like this for the triangle: <?php if ($a+$b <= $c || $a+$c <= $b || $b+$c <= $a) { echo "Error!"; } ?> Assuming that $a, $b and $c are your sides (if you start off with GET variables, just substitute them in). Link to comment https://forums.phpfreaks.com/topic/176630-solved-temperature-conversion-and-sides-of-a-triangle/#findComment-931263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.