summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrenton Stark <[email protected]>2022-11-05 12:01:16 -0700
committerTrenton Stark <[email protected]>2022-11-05 12:01:16 -0700
commit757851b3255f5734c9e78bd420686bbb6e87d440 (patch)
treecec932f9da964022c8b31008851093c8c75e1742
parentAdded temperature input system. (diff)
downloadcst116-lab2-stark-757851b3255f5734c9e78bd420686bbb6e87d440.tar.xz
cst116-lab2-stark-757851b3255f5734c9e78bd420686bbb6e87d440.zip
Move temperature input to a function.
-rw-r--r--BlankConsoleLab/cst116-lab2-stark.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/BlankConsoleLab/cst116-lab2-stark.cpp b/BlankConsoleLab/cst116-lab2-stark.cpp
index aca24a4..327cb11 100644
--- a/BlankConsoleLab/cst116-lab2-stark.cpp
+++ b/BlankConsoleLab/cst116-lab2-stark.cpp
@@ -14,18 +14,23 @@ 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;
+ inputTemp(cTemp, fTemp);
+}
+
+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;
- }
+ 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') {
@@ -50,10 +55,9 @@ int main() {
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;
@@ -66,8 +70,4 @@ float tempConverter(float temp, bool dirc) {
}
return cTemp;
-}
-
-void inputTemp(float& cTemp, float& fTemp) {
-
-}
+} \ No newline at end of file