Converting Temperature from Fahrenheit to Celsius and Kelvin with C# Console Application Programming

In this tutorial, we are going to see how to accept a temperature value in Fahrenheit from the keyboard and convert it into Celsius as well as Kelvin using C# programming.

Before we skip directly into the program, let’s know about the concept of conversion process at first.

Concept: Fahrenheit can be converted into Celsius using the following formula:
(No. of Fahrenheit units-32)*(5/9).

The same way, Fahrenheit units can be converted into Kelvin by using the following formula:
((No. of Fahrenheit units-32)/1.8)+273.15).

We are going to use this formulae in our following program to achieve the result.

using System.Text;

namespace TemperatureConversion
    class Program
        static void Main(string[] args)
            double temp;
            Console.Write("Enter temperature in Fahrenheit: ");
            temp = double.Parse(Console.ReadLine());
            Console.WriteLine("Temperature converted into Celsius: " + ((temp-32)*(5.0/9)));
            Console.WriteLine("Temperature converted into Kelvin: " + (((temp-32)/1.8)+273.15));
            Console.ReadLine(); /*used to make the console stop closing automatically after printing the output*/

Enter temperature in Fahrenheit: 56
Temperature converted into Celsius: 13.33
Temperature converted into Kelvin: 286.48

Points to remember:
  • As we are programming in console application, we see the result on the console only.
  • The reason why we used 5.0/9 in Celsius conversion is that it gives infinity if the values are taken in integer format.
  • The Console.ReadLine() in the last line of execution is used to make the console stop closing immediately after showing the result, else, it has nothing to do with the program logic.
Continue Reading