C# Examples
Dave Braunschweig
Temperature
// This program asks the user for a Fahrenheit temperature, // converts the given temperature to Celsius, // and displays the results. // // References: // https://www.mathsisfun.com/temperature-conversion.html // https://en.wikibooks.org/wiki/C_Sharp_Programming using System; class Temperature { public static void Main (string[] args) { double fahrenheit; double celsius; fahrenheit = GetFahrenheit(); celsius = CalculateCelsius(fahrenheit); DisplayResult(fahrenheit, celsius); } private static double GetFahrenheit() { string input; double fahrenheit; Console.WriteLine("Enter Fahrenheit temperature:"); input = Console.ReadLine(); fahrenheit = Convert.ToDouble(input); return fahrenheit; } private static double CalculateCelsius(double fahrenheit) { double celsius; celsius = (fahrenheit - 32) * 5 / 9; return celsius; } private static void DisplayResult(double fahrenheit, double celsius) { Console.WriteLine(fahrenheit.ToString() + "° Fahrenheit is " + celsius.ToString() + "° Celsius"); } }
Output
Enter Fahrenheit temperature: 100 100° Fahrenheit is 37.7777777777778° Celsius