diff options
| author | Trenton Stark <[email protected]> | 2022-11-05 11:59:58 -0700 |
|---|---|---|
| committer | Trenton Stark <[email protected]> | 2022-11-05 11:59:58 -0700 |
| commit | e389696aea64a2e2010f2293095c569ed6425043 (patch) | |
| tree | 792846851fb00bba54afc64a1e1685aa4466bbb9 | |
| parent | Renamed and added documentation. (diff) | |
| download | cst116-lab2-stark-e389696aea64a2e2010f2293095c569ed6425043.tar.xz cst116-lab2-stark-e389696aea64a2e2010f2293095c569ed6425043.zip | |
Added temperature input system.
| -rw-r--r-- | BlankConsoleLab/cst116-lab2-stark.cpp | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/BlankConsoleLab/cst116-lab2-stark.cpp b/BlankConsoleLab/cst116-lab2-stark.cpp index 2e0131f..aca24a4 100644 --- a/BlankConsoleLab/cst116-lab2-stark.cpp +++ b/BlankConsoleLab/cst116-lab2-stark.cpp @@ -8,8 +8,66 @@ using std::cout; using std::cin; using std::endl; -int main() -{ - cout << "Hello World!\n"; +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() { + char tempType; + float cTemp, fTemp; + + cout << "Welcome to Cold Calculator v0.2" << endl; + + 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 / 5)) + 32; + } + else { + cTemp = (temp - 32) * (5/9); + } + + return cTemp; +} + +void inputTemp(float& cTemp, float& fTemp) { + +} |