Convert Fahrenheit to Celsius

Program to convert temperature from Fahrenheit to Celsius

BeginnerTopic: Basic Programs
Back

C++ Convert Fahrenheit to Celsius Program

This program helps you to learn the fundamental structure and syntax of C++ programming.

Try This Code
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    float fahrenheit, celsius;
    
    cout << "Enter temperature in Fahrenheit: ";
    cin >> fahrenheit;
    
    // Formula: C = (F - 32) * 5/9
    celsius = (fahrenheit - 32) * 5.0 / 9.0;
    
    cout << fixed << setprecision(2);
    cout << fahrenheit << "°F = " << celsius << "°C" << endl;
    
    return 0;
}
Output
Enter temperature in Fahrenheit: 98.6
98.60°F = 37.00°C

Understanding Convert Fahrenheit to Celsius

This program demonstrates formula-based calculations. The conversion formula from Fahrenheit to Celsius is C = (F - 32) * 5/9. We use 5.0/9.0 to ensure floating-point division. The result is formatted to 2 decimal places.

Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.

Table of Contents