From eb5a168eca100a70d01572948c91c6b1d9c69633 Mon Sep 17 00:00:00 2001 From: Logan Date: Wed, 24 Apr 2024 19:10:44 -0700 Subject: Added Temperature Log --- CST 126/Homework 1/main.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) 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 +#include 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 -- cgit v1.2.3