[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