Fahrenheit and Celsius are the two temperature scales that are most commonly used. Most countries use the metric temperature system known as Celsius (symbol: °C). Under typical meteorological circumstances, water has a freezing point of 0 degrees Celsius and a boiling temperature of 100 degrees Celsius.
The United States and a few other countries predominantly use the Fahrenheit (symbol: °F) unit of measurement. According to the Fahrenheit scale, under typical climatic circumstances, water has a freezing point of 32 degrees Fahrenheit and a boiling temperature of 212 degrees Fahrenheit.
In this Answer, we will learn how to convert Celsius to Fahrenheit in C++.
Using the formula below, we can change the temperature from Celsius to Fahrenheit:
Here, is the Fahrenheit temperature and is the Celsius temperature.
Let’s have a look at the example below for a better understanding.
Let’s suppose we have a temperature of 28 degrees Celsius. Let’s put the value of in the formula above.
Given ,
Let’s see an example of converting a temperature in Celsius to Fahrenheit in C++:
#include <iostream>int main() {double c = 28;// Using the formuladouble f = (c * 9 / 5) + 32;std::cout << "After converting celsius to fahrenheit the value is " << f << std::endl;return 0;}
Here’s the line-to-line explanation of the code above:
Line 4: We declare a variable c
with the value of c
represents the temperature in Celsius.
Line 7: We calculate the temperature in Fahrenheit using the formula for converting Celsius temperatures to Fahrenheit. It multiplies the Celsius temperature (c
) by f
.
Line 8: We print the result.
Line 10: The code returns an exit status of 0
, indicating successful execution.
Free Resources