
//
// This is example code from Chapter 5.11 "Drill" of
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
/***3. Absolute zero is the lowest temperature that can be reached; it is –273.15°C, or 0K.
This program, even when corrected, will produce erroneous results when given a temperature
below this. Place a check in the main program that will produce an error if a temperature is
given below –273.15°C.

4. Do exercise 3 again, but this time handle the error inside ctok().
**/

#include "..\std_lib_facilities.h"

//------------------------------------------------------------------------------
double ctok(double c) { /// converts Celsius to Kelvin
    if(c < -273.15) error("That's pretty durn cold!");
    double k = c + 273.15;
    return k;
}

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 k = ctok(c); // convert temperature
    cout << "\nYour temperature in Kelvin: " << k << ' ' << '\n' ; // print out temperature
    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;
}

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