#include <iostream>
#include <string>
#include <vector>
#include <limits>
using namespace std;
// OrinTill Qimid CS1A Chapter 4, P. 294, 10
//
// /**************************************************************
// * Calculate Total Rainfall
// *
// * ____________________________________________________________
// * This program will calculate the average rainfall and the temperature.
// * ____________________________________________________________
// * INPUT
// * Total Rainfall
// * OUTPUT
// * Average montly temperatures.
// **************************************************************/
// Define the MonthlyBudget structure
struct WeatherData {
double totalRainfall;
double highTemperature;
double lowTemperature;
double averageTemperature;
};
int main() {
const int MONTHS = 12;
vector<WeatherData> year(MONTHS);
double totalRainfall = 0.0;
double totalAverageTemperature = 0.0;
double highestTemperature = numeric_limits<double>::lowest();
double lowestTemperature = numeric_limits<double>::max();
int highestTempMonth = -1;
int lowestTempMonth = -1;
string monthNames[MONTHS] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
// Input weather data for each month
for (int i = 0; i < MONTHS; ++i) {
cout << "Enter data for " << monthNames[i] << ":\n";
cout << "Total Rainfall (in inches): ";
cin >> year[i].totalRainfall;
cout << "High Temperature (in Fahrenheit): ";
cin >> year[i].highTemperature;
cout << "Low Temperature (in Fahrenheit): ";
cin >> year[i].lowTemperature;
// Calculate average temperature
year[i].averageTemperature = (year[i].highTemperature + year[i].lowTemperature) / 2.0;
totalRainfall += year[i].totalRainfall;
totalAverageTemperature += year[i].averageTemperature;
// Determine highest and lowest temperatures
if (year[i].highTemperature > highestTemperature) {
highestTemperature = year[i].highTemperature;
highestTempMonth = i;
}
if (year[i].lowTemperature < lowestTemperature) {
lowestTemperature = year[i].lowTemperature;
lowestTempMonth = i;
}
cout << "\n";
}
// Calculate average monthly rainfall
double averageMonthlyRainfall = totalRainfall / MONTHS;
double averageOfMonthlyAverages = totalAverageTemperature / MONTHS;
// Display results
cout << "\nYearly Weather Summary:\n";
cout << "Total Rainfall for the year: " << totalRainfall << " inches\n";
cout << "Average Monthly Rainfall: " << averageMonthlyRainfall << " inches\n";
cout << "Highest Temperature: " << highestTemperature << " F (" << monthNames[highestTempMonth] << ")\n";
cout << "Lowest Temperature: " << lowestTemperature << " F (" << monthNames[lowestTempMonth] << ")\n";
cout << "Average of Monthly Average Temperatures: " << averageOfMonthlyAverages << " F\n";
return 0;
}