summaryrefslogtreecommitdiff
path: root/BlankConsoleLab
diff options
context:
space:
mode:
authorMusa Ahmed <[email protected]>2022-11-09 20:28:38 -0800
committerMusa Ahmed <[email protected]>2022-11-09 20:28:38 -0800
commit1ba25646119ebaad25b76f21742604fa8e152ff7 (patch)
tree85a94697ce85cb63476fe69c58c1d454609477a8 /BlankConsoleLab
parentadded comments for each function (diff)
downloadcst116-lab2-m005a-1ba25646119ebaad25b76f21742604fa8e152ff7.tar.xz
cst116-lab2-m005a-1ba25646119ebaad25b76f21742604fa8e152ff7.zip
Fixed an error in windchill function and redid comment
Diffstat (limited to 'BlankConsoleLab')
-rw-r--r--BlankConsoleLab/CST116-Lab2-Ahmed-Pseudocodetxt.txt8
-rw-r--r--BlankConsoleLab/CST116-Lab2-Ahmed.cpp24
2 files changed, 21 insertions, 11 deletions
diff --git a/BlankConsoleLab/CST116-Lab2-Ahmed-Pseudocodetxt.txt b/BlankConsoleLab/CST116-Lab2-Ahmed-Pseudocodetxt.txt
index 58c9381..8235fbe 100644
--- a/BlankConsoleLab/CST116-Lab2-Ahmed-Pseudocodetxt.txt
+++ b/BlankConsoleLab/CST116-Lab2-Ahmed-Pseudocodetxt.txt
@@ -63,9 +63,13 @@ cToF function definition
returns temp
windChill function definition
- Takes an input of d and w by reference
+ Takes an input of d and w and boolean x by reference
initializes a variable out to a float
- sets float equal to the calculation to get the windchill
+ if x is false
+ set out equal to the calculation to get the windchill and converts celsius to fahrenheit using cToF
+ else
+ set out equal to the calculation to get the windchill
+
output function definition
takes an input of a float d, w, chill, and a boolean x (by value)
diff --git a/BlankConsoleLab/CST116-Lab2-Ahmed.cpp b/BlankConsoleLab/CST116-Lab2-Ahmed.cpp
index 8180237..67c3909 100644
--- a/BlankConsoleLab/CST116-Lab2-Ahmed.cpp
+++ b/BlankConsoleLab/CST116-Lab2-Ahmed.cpp
@@ -18,9 +18,15 @@ float cToF(float a) {
float temp = (9.0 / 5) * a + 32;
return temp;
}
-// Function name windChill, inputs a float d and w by reference, returns a float out
-float windChill(float& d, float& w) {
- float out = 35.74 + 0.6215 * d - 35.75 * pow(w, 0.16) + 0.4275 * d * pow(w, 0.16);
+// Function name windChill, inputs a float d, w, and boolean x by reference, returns a float out
+float windChill(float& d, float& w, bool& x) {
+ float out;
+ if (x == false) {
+ out = 35.74 + 0.6215 * cToF(d) - 35.75 * pow(w, 0.16) + 0.4275 * cToF(d) * pow(w, 0.16);
+ }
+ else {
+ out = 35.74 + 0.6215 * d - 35.75 * pow(w, 0.16) + 0.4275 * d * pow(w, 0.16);
+ }
return out;
}
// Function name output, inputs floats d, w, chill, and boolean x, returns a string containing the complete output
@@ -42,8 +48,8 @@ int main()
const int MAXF = 121;
const int MINC = -62;
const float MAXC = 49.5;
- float c = 0;
- float f = 0;
+ float c = -100;
+ float f = 200;
float w;
string temp;
bool range = false;
@@ -103,15 +109,15 @@ int main()
}
- if (c != 0) {
+ if (c != -100) {
isF = false;
- cout << setprecision(2) << output(c, w, windChill(c, w), isF);
+ cout << setprecision(2) << output(c, w, windChill(c, w, isF), isF);
}
- else if (f != 0) {
+ else if (f != 200) {
isF = true;
- cout << setprecision(2) << output(f, w, windChill(f, w), isF);
+ cout << setprecision(2) << output(f, w, windChill(f, w, isF), isF);
}