C++ Exercises: Convert temperature in Fahrenheit to Celsius
Fahrenheit to Celsius Conversion
Write a C++ program to convert temperature in Fahrenheit to Celsius.
Sample Solution:
C++ Code :
#include <iostream> // Including the input-output stream header file
using namespace std; // Using the standard namespace
int main() // Start of the main function
{
float frh, cel; // Declaring floating-point variables for Fahrenheit and Celsius temperatures
cout << "\n\n Convert temperature in Fahrenheit to Celsius :\n"; // Outputting a message indicating temperature conversion
cout << "---------------------------------------------------\n"; // Outputting a separator line
cout << " Input the temperature in Fahrenheit : "; // Prompting the user to input the temperature in Fahrenheit
cin >> frh; // Taking input for the Fahrenheit temperature from the user
cel = ((frh * 5.0) - (5.0 * 32)) / 9; // Converting Fahrenheit to Celsius using the formula: (Fahrenheit - 32) * 5/9
cout << " The temperature in Fahrenheit : " << frh << endl; // Displaying the input temperature in Fahrenheit
cout << " The temperature in Celsius : " << cel << endl; // Displaying the converted temperature in Celsius
cout << endl; // Outputting a blank line for better readability
return 0; // Returning 0 to indicate successful program execution
} // End of the main function
Sample Output:
Convert temperature in Fahrenheit to Celsius : --------------------------------------------------- Input the temperature in Fahrenheit : 95 The temperature in Fahrenheit : 95 The temperature in Celsius : 35
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C++ program to convert a temperature from Fahrenheit to Celsius and verify the conversion with a reverse calculation.
- Write a C++ program that reads a Fahrenheit temperature, converts it to Celsius, and then displays the result with a precision of two decimals.
- Write a C++ program to implement a function that converts Fahrenheit to Celsius and uses it to convert multiple values stored in an array.
- Write a C++ program that accepts a Fahrenheit temperature, converts it to Celsius, and then prints a message indicating if the temperature is below freezing.
C++ Code Editor:
Previous: Write a program in C++ to convert temperature in Celsius to Fahrenheit.
Next: Write a program in C++ to find the third angle of a triangle.
What is the difficulty level of this exercise?