// Trenton Stark // CST-116 // Lab 2 #include using std::cout; using std::cin; using std::endl; float tempConverter(float temp, bool dirc); void inputTemp(float& cTemp, float& fTemp); const float fMin = -80, fMax = 121, cMin = -62, cMax = 49.5, wMin = 0, wMax = 231; //Minimum and maximum valid ranges for all user inputs int main() { float cTemp, fTemp; cout << "Welcome to Cold Calculator v0.2" << endl; inputTemp(cTemp, fTemp); cout << cTemp << endl; cout << fTemp << endl; } void inputTemp(float& cTemp, float& fTemp) { char tempType; cout << "Would you like to enter the temperature in Celcius (c) or Fahrenehit (f)?" << endl; do { cin >> tempType; cout << endl; if (tempType != 'f' && tempType != 'c') { cout << "Input the character 'c' or 'f'!" << endl; } } while (tempType != 'f' && tempType != 'c'); if (tempType == 'c') { cout << "What is the temperature in Celcius (-62 - 49.5 degrees)?" << endl; do { cin >> cTemp; cout << endl; if (cTemp < cMin || cTemp > cMax) { cout << "Input a value between -62 and 49.5 degrees!" << endl; } fTemp = tempConverter(cTemp, 0); } while (cTemp < cMin || cTemp > cMax); } else { cout << "What is the temperature in Fahrenheit (-80 - 121 degrees)?" << endl; do { cin >> fTemp; cout << endl; if (fTemp < fMin || fTemp > fMax) { cout << "Input a value between -80 and 121 degrees!" << endl; } cTemp = tempConverter(fTemp, 1); } while (fTemp < fMin || fTemp > fMax); } } // Direction is 0 if going celcius to fahrenheit and 1 if going fahrenheit to celcius float tempConverter(float temp, bool dirc) { float cTemp; if (dirc == 0) { cTemp = (temp * (9.0 / 5.0)) + 32; } else { cTemp = (temp - 32) * (5.0 / 9.0); } return cTemp; }