#ifndef TEMPERATURE_H #define TEMPERATURE_H #include #include "clear.hpp" using std::cout; using std::cin; using std::endl; struct temp { float high; float low; }; inline void Day(int num) { switch (num) { case 1: cout << "Sunday"; break; case 2: cout << "Monday"; break; case 3: cout << "Tuesday"; break; case 4: cout << "Wednesday"; break; case 5: cout << "Thursday"; break; case 6: cout << "Friday"; break; case 7: cout << "Saturday"; break; default: cout << "Error"; } } inline void Populate(temp temperature[], int size) { for (int i = 1; i < size; i++) { cout << "\nWhat is the high temp for "; Day(i); cout << "?: "; cin >> temperature[i].high; cout << "\nWhat is the low temp for "; Day(i); cout << "?: "; cin >> temperature[i].low; } } inline void AvgHiLo(const temp temperature[], const int size, float &averageHigh, float &averageLow, float &high, float &low, float &diff) { float placeholder; float count = 0; high = temperature[1].high; low = temperature[1].low; for (int i = 1; i < size; i++) { placeholder = temperature[i].high - temperature[i].low; if (diff < placeholder) diff = placeholder; if (high < temperature[i].high) high = temperature[i].high; if (low > temperature[i].low) low = temperature[i].low; averageHigh = averageHigh + temperature[i].high; averageLow = averageLow + temperature[i].low; count++; } averageHigh = averageHigh / count; averageLow = averageLow / count; } inline bool MoreTemps() { char again; cout << "\nWould you like to log more temperatures? (Y/N): "; cin >> again; if (again == 'Y') return true; else return false; } inline void StoreTemp() { const int size = 8; temp temperature[size]; float avgHi = 0; float avgLo = 0; float highest = 0; float lowest = 0; float diff = 0; ClearScreen(); cout << "*************************************************************\n"; cout << "Welcome to the temperature logger!\nYou will be prompted to enter the high and low temp for each day of the week.\n"; Populate(temperature, size); AvgHiLo(temperature, size, avgHi, avgLo, highest, lowest, diff); ClearScreen(); cout << "The highest temp was:\n" << highest; cout << "\nThe lowest temp was:\n" << lowest; cout << "\nThe average high temp was:\n" << avgHi; cout << "\nThe average low temp was:\n" << avgLo; cout << "\nThe greatest difference in temp was:\n" << diff; if (MoreTemps() == true) StoreTemp(); } #endif