#include #include using namespace std; int main() { // int double float char <== built-in data types // (primitive data types) // i.e. built-in to the C++ language // char user_input; string user_input; cout << "Enter either 'fahr' or 'celsius': "; cin >> user_input; double fahr, celsius; // boolean data type -- true (non-zero), false (0) bool is_user_input_valid = false; if ( user_input == "fahr" || user_input == "fahrenheit" || user_input == "f" ) { is_user_input_valid = true; cout << "Please enter Fahrenheit value: "; cin >> fahr; celsius = ( fahr - 32 ) * ( 5.0 / 9.0 ); cout << "Converted to Centigrade: " << celsius << endl; } else if ( user_input == "celsius" ) { is_user_input_valid = true; cout << "Please enter Centigrade value: "; cin >> celsius; fahr = ( 9.0 / 5.0 ) * celsius + 32; cout << "Converted to Fahrenheit: " << fahr << endl; } else { is_user_input_valid = false; // cout << "Can't you read directions???" << endl; cerr << "Can't you read directions???" << endl; // return -1; // exit the program } if ( is_user_input_valid ) { // if we're inside this if statement, then // the user typed in a valid string to begin with.... if ( fahr == 32 ) { cout << "Pure water freezes at this temperature.\n"; } // etc. } return 0; }