// Celsius.cpp - a quick 1st example of a program // // Temperature Conversion // // This test program asks for the user's name, // and a temperature in degrees Fahrenheit. // The output is the temperature in degrees Celsius. // // ---------------------------------------------------------------------------- #include #include using namespace std ; // adds all preceding declarations in the // std namespace to the global namespace // a C++ stmt., not a preprocessor directive // Constants used in temperature conversion // These are global. We'll discuss this more later const float FAHRENHEIT_BASE = 32.0; const float F2C_SCALE = 1.8; // ------------------------------- Main ------------------------------- int main() { // --------------------------------------------------------------------- // Variables: // fahrenheit is the temperature in degrees Fahrenheit. // celsius is the temperature in degrees Celsius. // name is the user's first name // --------------------------------------------------------------------- float fahrenheit, celsius; string firstName ; cout << "Hello, what is your first name? => "; cin >> firstName; cout << endl; cout << "\nHello, " << firstName << ", please enter a temperature in Fahrenheit) => "; cin >> fahrenheit; cout << endl; celsius = ( fahrenheit - FAHRENHEIT_BASE ) / F2C_SCALE; cout << "The corresponding temperature in celsius is: " << celsius << " .\n" << endl; return 0; }