Computer Programming/Variables/C++

From Wikiversity
Jump to navigation Jump to search

variables.cpp[edit]

// This program converts a Fahrenheit temperature to Celsius.
//
// References:
//     https://www.mathsisfun.com/temperature-conversion.html
//     https://en.wikibooks.org/wiki/C%2B%2B_Programming

#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]