C++ Program to Convert Fahrenheit to Celsius

In this post, we will learn how to convert Fahrenheit to Celsius using the C++ Programming language.

The formula used to convert temperature from degree Fahrenheit to degree Celsius is:

  • C = (F – 32) x 5/9

where C is the temperature in Celsius and F is the temperature in Fahrenheit.

We will convert the temperature from Fahrenheit to Celsius using the above conversion formula.

So, without further ado, let’s begin this tutorial.

C++ Program to Convert Fahrenheit to Celsius

C++ Program

// C++ Program to Convert Fahrenheit to Celsius
#include <iostream>
using  namespace std;

int main(){
    float fahren, celsius;
    
    // Asking for input
    cout << "Enter the temperature in degree Fahrenheit: ";
    cin >> fahren;
    
    // Fahrenheit to celsius 
    celsius = (fahren - 32) * 5/9;
    
    // Display output
    cout << "The temperature in degree Celsius: " << celsius << endl;
    return 0;
}

Output

Enter the temperature in degree Fahrenheit: 101.7
The temperature in degree Celsius: 38.7222

How Does This Program Work?

    float fahren, celsius;

In this program, we have declared two floating data type variables named fahren and celsius.

    // Asking for input
    cout << "Enter the temperature in degree Fahrenheit: ";
    cin >> fahren;

Then, the user is asked to enter the temperature in degree Fahrenheit.

    // Fahrenheit to celsius 
    celsius = (fahren - 32) * 5/9;

We convert the temperature from degree Fahrenheit to degree Celsius using the formula: C = (F – 32) x 5/9.

    // Display output
    cout << "Temperature in degree Celsius: " << celsius << endl;

After that, the temperature in degree Celsius is displayed on the screen using the cout statement.

Conclusion

I hope after going through this post, you understand how to convert Fahrenheit to Celsius using the C++ Programming language.

If you have any doubt regarding the program, then contact us in the comment section. We will be delighted to assist you.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *