Introduction:
Temperature conversion is a common task in programming, especially in applications dealing with weather, physics, or engineering. In this article, we’ll explore a C++ Program to Convert Temperature from Fahrenheit to Celsius. Understanding this conversion is essential for anyone working with temperature data or systems that use different temperature scales.
Temperature conversion is provided below.
C = (F - 32) * 5/9
1. Temperature Conversion Program
1.1 Program Code:
#include <iostream>
using namespace std;
int main() {
double fahrenheit, celsius;
cout << "Enter temperature in Fahrenheit: ";
cin >> fahrenheit;
// Convert Fahrenheit to Celsius using the formula: (F - 32) * 5/9
celsius = (fahrenheit - 32) * 5.0 / 9.0;
cout << "Temperature in Celsius: " << celsius << " degrees Celsius" << endl;
return 0;
}
1.2 Sample Output:
Enter temperature in Fahrenheit: 98.6
Temperature in Celsius: 37 degrees Celsius
Explanation:
- The program prompts the user to enter the temperature in Fahrenheit.
- It reads the input using
cin
. - The temperature is converted from Fahrenheit to Celsius using the formula
(F - 32) * 5/9
, whereF
is the temperature in Fahrenheit. - The converted temperature in Celsius is then displayed using
cout
.
Conclusion:
In this article, we’ve demonstrated a simple yet powerful C++ program to convert temperature from Fahrenheit to Celsius. This conversion is based on a fundamental formula and is commonly used in various applications. Understanding temperature conversions and implementing them in programming can be valuable in many domains, including weather forecasting, scientific research, and engineering.