Computer Programming/Variables/C++

From Wikiversity
Jump to: navigation, search

variables.cpp[edit]

// This program converts a Fahrenheit temperature to Celsius.

#include <iostream>

using namespace std;

int main() 
{
    double f;
    double c;
    
    cout << "Enter Fahrenheit temperature:" << endl;
    cin >> f;

    c = (f - 32) * 5 / 9;

    cout << f << "° Fahrenheit is " << c << "° Celsius" << endl;

    return 0;
}

Try It[edit]

Copy and paste the code above into one of the following free online development environments or use your own C++ compiler / interpreter / IDE.

See Also[edit]