1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Help With Function in PHP

Discussion in 'Programming & Webmastering' started by Hale88, Dec 5, 2009.

  1. Hale88 New Member

    Joined:
    Sep 4, 2009
    Messages:
    153 (0.09/day)
    Thanks Received:
    3
    Location:
    Somewhere in FL
    I really need help in this assignment since Function is so complicated. I only understand around 70% of it.
    here is the assingment: Please write it in basic code so I can learn more and modify it later on

    "Write a function called Celsius that accepts one argument for the Fahrenheit temperature and returns the value of the Fahrenheit temperature converted to Celsius.
    Here is the formula to convert a Fahrenheit temperature to Celsius
    C = 5 / 9 * (F – 32)
    To use this function create a for loop that goes from 0 to 100.
    In each iteration of the loop
    • call the Celsius function passing the function the loop counter
    • print the loop counter and the value returned from the Celsius function on the same line
    This will create a list where the first number represents the Fahrenheit temperature and the second number represents the corresponding Celsius temperature."

    thank you much
  2. Kreij

    Kreij Senior Monkey Moderator Staff Member

    Joined:
    Feb 6, 2007
    Messages:
    13,881 (5.27/day)
    Thanks Received:
    5,610
    Location:
    Cheeseland (Wisconsin, USA)
    No offense, Hale88, but you really need to give it a little effort. You can write this whole thing in 4 lines of code.

    I'm feeling generous this morning so here is a C# version ...
    Code:
    
    for (i = 0; i <= 100; i++)
    {
        Console.Writeln("Fahrenheit : " + i + "    Celsius : " + Celsius(i).ToString());
    }
    
    float Celsius (int Fahrenheit)
    {
        return 5 / 9 * (Fahrenheit - 32);
    }
    

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page