C++ Program to Convert Celsius to Fahrenheit

In this post, we will learn how to convert Celsius to Fahrenheit using the C++ Programming language.

The below program asks the user to enter the temperature in degree Celsius, then it converts the temperature into degree Fahrenheit using the formula: F = (C x 9/5) + 32, where C is the temperature in degree Celsius.

So, without further ado, let’s begin this tutorial. 

C++ Program to Convert Celsius to Fahrenheit

// C++ Program to Convert Celsius to Fahrenheit
#include <iostream>
using namespace std;

int main(){
    float celsius, fahrenheit;
    
    // Asking for input
    cout << "Enter the temperature in Celsius: ";
    cin >> celsius;
    
    // Celsius to fahrenheit
    fahrenheit = (celsius * 9.0) / 5.0 + 32;
    
    // Display result
    cout << "The temperature in degree Fahrenheit: " << fahrenheit << endl;
    
    return 0;
}

Output

Enter the temperature in Celsius: 40.6
The temperature in degree Fahrenheit: 105.08

How Does This Program Work?

    float celsius, fahrenheit;

In this program, we have declared two floating data type variables named celsius and fahrenheit.

    // Asking for input
    cout << "Enter the temperature in Celsius: ";
    cin >> celsius;

Then, the user is asked to enter the temperature in degree Celsius.

    // Celsius to fahrenheit
    fahrenheit = (celsius * 9.0) / 5.0 + 32;

The temperature is converted from degree Celsius to degree Fahrenheit using the conversion formula: F = (C x 9/5) + 32.

    // Display result
    cout << "The temperature in degree Fahrenheit: " << fahrenheit << endl;

Finally, the equivalent temperature in degree Fahrenheit is printed on the screen using the cout statement. 

Conclusion

I hope after going through this post, you understand how to convert Celsius to Fahrenheit using the C++ Programming language.

If you have any doubt regarding the program, then contact us in the comment section. We will be delighted to assist you.

Also Read:

Leave a Comment

Your email address will not be published.