DevPinoy.org
A Filipino Developers Community
   
HowTo: Convert Celsius To Fahrenheit and vice-versa

[code language="C#"]

using System;
using System.Collections.Generic;
using System.Text;

namespace KeithRull.CS.Windows.DevCenterConsole
{
    class TemperatureCalculation
    {
        static void Main(string[] args)
        {
            this.ShowCalculation();
        }

        public void ShowCalculation()
        {
            double celsius = 44.5;

            double fahrenheit = CelsiusToFahrenheit(celsius);

            Console.WriteLine(fahrenheit);

            celsius = FahrenheitToCelsius(fahrenheit);

            Console.WriteLine(celsius);
        }

        //formulas are taken from
        //http://vathena.arc.nasa.gov/curric/weather/fahrcels.html

        public static double CelsiusToFahrenheit(double celsius)
        {
            /*
                Tc=(5/9)*(Tf-32)
                Tc=temperature in degrees Celsius
                Tf=temperature in degrees Fahrenheit
             * */
            return (((0.9 / 0.5) * celsius) + 32);
        }

        public static double FahrenheitToCelsius(double fahrenheit)
        {
            /*
                Tf=(9/5)*Tc+32
                Tc=temperature in degrees Celsius
                Tf=temperature in degrees Fahrenheit
              */
            return ((0.5 / 0.9) * (fahrenheit + 32));
        }
    }
}

[/code]


Posted 05-18-2006 4:50 PM by keithrull
Filed under:

Comments

jokiz wrote re: HowTo: Convert Celsius To Fahrenheit and vice-versa
on 05-18-2006 9:36 PM
hey keith, comments are misplaced and it is worth noting that you used the double for the ratio (e.g. 0.5/0.9) to avoid integer division (5/9 = 0, 9/5 = 1)
keithrull wrote re: HowTo: Convert Celsius To Fahrenheit and vice-versa
on 05-18-2006 9:55 PM
heheh! yeah! true.

i think i was my boring day today that made me do this code. good analogy jokiz.
dfghjk,lfghjkl;lkjdgdhjkljhgfd wrote re: HowTo: Convert Celsius To Fahrenheit and vice-versa
on 11-08-2007 3:10 PM

wsedrftghj

milo wrote re: HowTo: Convert Celsius To Fahrenheit and vice-versa
on 09-26-2008 12:54 AM

NERDS!!!

Copyright DevPinoy 2005-2008