
//
// This is example code from Chapter 5.11 "Drill" of
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
/***36. Write a program that converts from Celsius to Fahrenheit and
from Fahrenheit to Celsius (formula in §4.3.3). Use estimation (§5.8)
to see if your results are plausible.
**/

#include "..\std_lib_facilities.h"

//------------------------------------------------------------------------------
double ctof(double c) { /// converts Celsius to Fahrenheit
    double f = 9*c/5 + 32;
    return f;
}

double ftoc(double f) { /// converts Celsius to Fahrenheit
    double c = 5*(f-32)/9;
    return c;
}

int main()
try {
    double c = 0; /// declare input variable
    cout << "\nInput temperature in Celsius: ";
    cin >> c; /// retrieve temperature to input variable
    //if(c < -273.15) error("That's pretty durn cold!");
    double f = ctof(c); // convert temperature
    cout << "\nYour temperature in Fahrenheit: " << f << ' ' << '\n' ; // print out temperature
    cout << "\nTo be sure, your original Celsius temperature was " << ftoc(f);
    return 0;
}

catch (exception& e) {
    cerr << "error: " << e.what() << '\n';
    keep_window_open();
    return 1;
}
catch (...) {
    cerr << "Oops: unknown exception!\n";
    keep_window_open();
    return 2;
}

//------------------------------------------------------------------------------

