C++ Code Example: convert celsius to fahrenheit

This code converts a temperature from Celsius to Fahrenheit.

The main function starts by declaring two double variables, c and f, to represent the temperatures in Celsius and Fahrenheit, respectively.

Next, the program prompts the user to input the temperature in Celsius using cout and stores the value in the c variable using cin.

The temperature conversion formula from Celsius to Fahrenheit is then applied: f = c * 1.8 + 32. This formula multiplies the Celsius temperature by 1.8 and then adds 32 to it.

Finally, the converted temperature in Fahrenheit is printed to the console using cout. The program ends by returning a value of 0 to indicate successful execution.

#include <iostream>
using namespace std;

int main() {
    double c, f;

    cout << "Please enter temperature in celsius: ";
    cin >> c;

    f = c * 1.8 + 32;

    cout << "Temperature in fahrenheit: " << f << endl;

    return 0;
Please enter temperature in celsius: 10
Temperature in fahrenheit: 50