How to convert Celsius to Fahrenheit in C++

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++.

Conversion formula

Using the formula below, we can change the temperature from Celsius to Fahrenheit:

F=(C×95)+32F = \left(C \times \frac{9}{5} \right) + 32

Here, FF is the Fahrenheit temperature and CC is the Celsius temperature.

Let’s have a look at the example below for a better understanding.

Example

Let’s suppose we have a temperature of 28 degrees Celsius. Let’s put the value of CC in the formula above.

Given C=28°CC = 28\degree C,

F=(C×95)+32=(28×95)+32=(28×1.8)+32=50.4+32=82.4°F\begin{split} F & = \left(C \times \frac{9}{5} \right) + 32 \\ & = \left(28 \times \frac{9}{5} \right) + 32 \\ & = (28 \times 1.8) + 32 \\ & = 50.4 + 32 \\ & = 82.4 \degree F \end{split}

Implementation

Let’s see an example of converting a temperature in Celsius to Fahrenheit in C++:

#include <iostream>
int main() {
double c = 28;
// Using the formula
double f = (c * 9 / 5) + 32;
std::cout << "After converting celsius to fahrenheit the value is " << f << std::endl;
return 0;
}

Code explanation

Here’s the line-to-line explanation of the code above:

  • Line 4: We declare a variable c with the value of 2828, where 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 9/59/5 and adds 3232 to the result. The calculated Fahrenheit temperature is stored in the variable f.

  • Line 8: We print the result.

  • Line 10: The code returns an exit status of 0, indicating successful execution.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved