Fahrenheit to Celsius using C++

Fahrenheit and Celsius are units of measurement for temperature. Most countries use the Celsius scale as the official unit of measurement for temperature, only a few countries prefer the Fahrenheit scale. So, if you want to learn how to convert the temperature in Fahrenheit to Celsius, this article is for you. In this article, I will take you through how to write a program to convert the temperature in Fahrenheit to Celsius using C++.

Fahrenheit to Celsius using C++

The Celsius scale is based on the freezing point of water at 0 degrees Celsius and the boiling of water at 100 degrees Celsius, while the Fahrenheit scale is based on the freezing point of water at 32 degrees Fahrenheit and the boiling of water at 212 degrees Fahrenheit. Mathematically, if you want to convert Fahrenheit to Celsius, you have to use the formula mentioned below:

  • Temperature in Celsius = (Temperature in Fahrenheit – 32) x 5/9

Hope you now understand what Fahrenheit and Celsius are, how these two temperature units are different. Now, here’s how you can write a program to convert temperature from Fahrenheit to Celsius using C++:

Enter the Temperature in Fahrenheit :97
Temperature in Celsius = 36.1111

In the above code, I have first introduced two variables as float:

  1. ftemp for taking a user input as the temperature in Fahrenheit
  2. ctemp for storing the converted value of Fahrenheit to Celsius

Then I am simply asking for the temperature in Fahrenheit as user input and calculating its conversation in Celsius by using the mathematical formula mentioned above.

Summary

So this is how you can write a program to convert the temperature in Fahrenheit to Celsius using C++. The Celsius scale is based on the freezing point of water at 0 degrees Celsius and the boiling of water at 100 degrees Celsius, while the Fahrenheit scale is based on the freezing point of water at 32 degrees Fahrenheit and the boiling of water at 212 degrees Fahrenheit. I hope you liked this article on Fahrenheit to Celsius using C++. Feel free to ask your valuable questions in the comments section below.

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1534

2 Comments

Leave a Reply