diff options
| -rw-r--r-- | CST 126/Homework 1/main.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp index b008cd8..18c9225 100644 --- a/CST 126/Homework 1/main.cpp +++ b/CST 126/Homework 1/main.cpp @@ -4,6 +4,7 @@ // Assignment: Homework 1 #include <iostream> +#include <string> using namespace std; void moneyConverter(); @@ -106,5 +107,50 @@ void guessingGame() { } void temperatureLog() { + struct Temperature { + float high; + float low; + }; + Temperature weeklyLog[7]; + + for (int i = 0; i < 7; ++i) { + cout << "Day " << i + 1 << ":\n"; + cout << "Enter high temperature: "; + cin >> weeklyLog[i].high; + cout << "Enter low temperature: "; + cin >> weeklyLog[i].low; + } + + float totalHigh = 0, totalLow = 0; + for (int i = 0; i < 7; ++i) { + totalHigh += weeklyLog[i].high; + totalLow += weeklyLog[i].low; + } + float averageHigh = totalHigh / 7; + float averageLow = totalLow / 7; + + float largestDifference = 0; + for (int i = 0; i < 7; ++i) { + float difference = weeklyLog[i].high - weeklyLog[i].low; + if (difference > largestDifference) { + largestDifference = difference; + } + } + float lowestTemp = weeklyLog[0].low; + float highestTemp = weeklyLog[0].high; + for (int i = 1; i < 7; ++i) { + if (weeklyLog[i].low < lowestTemp) { + lowestTemp = weeklyLog[i].low; + } + if (weeklyLog[i].high > highestTemp) { + highestTemp = weeklyLog[i].high; + } + } + + cout << "\nAverage high temperature for the week: " << averageHigh << endl; + cout << "Average low temperature for the week: " << averageLow << endl; + cout << "Largest difference in a day's high/low: " << largestDifference << endl; + cout << "Lowest temperature of the week: " << lowestTemp << endl; + cout << "Highest temperature of the week: " << highestTemp << endl; }
\ No newline at end of file |