In: Computer Science
Instructions
Write a program in C# that converts a temperature given in Fahrenheit to Celsius. Allow the user to enter values for the original Fahrenheit value. Display the original temperature and the formatted converted value. Use appropriate value returning methods for entering (input), calculating, and outputting results.
Code:
using System;
class Fahrenheit
{
static double fahrenheitToCelcius(double fahrenheit)
{
double div=5.0/9;
return((fahrenheit-32)*div);
/*Here we return the Celcius temparature of the fahrenheit temparature*/
}
static void Main()
{
double fahrenheit;
Console.Write("Enter temparature in fahrenheit: ");
fahrenheit=Single.Parse(Console.ReadLine());
/*Reading fahrenheit temparature from the user*/
Console.Write(fahrenheit+" Degree Fahrenheit ="+fahrenheitToCelcius(fahrenheit)+" Degree Celcius");
/*Printing the result by calling the method fahrenheitToCelcius*/
}
}
Output:
Indentation: