List of Fahrenheit temps with Celsius equivalents

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

List of Fahrenheit temps with Celsius equivalents

Postby Nootch » Sat Apr 23, 2011 5:20 pm

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.
Syntax: [ Download ] [ Hide ]
<?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;
        }
?>
 
Nootch
Forum Newbie
 
Posts: 2
Joined: Sat Apr 23, 2011 5:02 pm

Re: List of Fahrenheit temps with Celsius equivalents

Postby califdon » Sat Apr 23, 2011 6:54 pm

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:
Syntax: [ Download ] [ Hide ]
<?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.
I don't make syntax errors. It's just that sometimes whoever wrote the programming language failed to anticipate my creative coding.
User avatar
califdon
Jack of Zircons
 
Posts: 4484
Joined: Thu Nov 09, 2006 9:30 pm
Location: California, USA

Re: List of Fahrenheit temps with Celsius equivalents

Postby Nootch » Sat Apr 23, 2011 9:09 pm

Thank you so much Califdon, works excellently. Thank you also for the pointer on my conversion algorithms, I see the light now.
Nootch
Forum Newbie
 
Posts: 2
Joined: Sat Apr 23, 2011 5:02 pm


Return to PHP - Code

Who is online

Users browsing this forum: No registered users and 14 guests