Page 1 of 1

List of Fahrenheit temps with Celsius equivalents

Posted: Sat Apr 23, 2011 5:20 pm
by Nootch
Hi everyone,
I am new at writing in php, first and foremost.
I am attempting to display a list of 0-100 degrees Fahrenheit, with its equivalent value in Celsius. I made these little functions to convert the temps, but I'm stumped on how to show them side by side (or one under the other) in a list on the page. If anyone knows a good way to do this, I would be much obliged.

Code: Select all

<?php
	function tempCtoF($c)
	{
		$f = $c * (9.0/5.0) + 32;
		return $f;
	}
        function tempFtoC($f)
        {
                $c = $f * (5.0/9.0) - 32;
		return $c;
        }
?>

Re: List of Fahrenheit temps with Celsius equivalents

Posted: Sat Apr 23, 2011 6:54 pm
by califdon
Probably the easiest way would be to create an HTML table. Increment the cell in the left column by one for each row. Something like this:

Code: Select all

<?php
echo "<table>";
for($n=0; $n <= 100; $n++) {
   echo "tr><td>$n</td><td>".tempFtoC($n)."</td></tr>";
}
echo "</table>";
But I don't think your conversion algorithms are correct. Try substituting a couple of trial numbers (say, for freezing) and you will see what I mean. And you only need one of them, unless you are going to create 2 tables.

Re: List of Fahrenheit temps with Celsius equivalents

Posted: Sat Apr 23, 2011 9:09 pm
by Nootch
Thank you so much Califdon, works excellently. Thank you also for the pointer on my conversion algorithms, I see the light now.