//Mia Agramon CS1A Chapter 11, P.646, #4
//
/*******************************************************************************
* Weather Statistics
* _____________________________________________________________________________
* This program will display total rainfall, high temperature, low temperature,
* average temperature for the year.
*
* INPUT
* total rainfall
* highest temperature
* lowest temperature
*
* OUTPUT
* average temperature
* average rainfall
* total rainfall
* highest temperature
* lowest temperature
* month with the highest temperature
* month with the lowest temperature
******************************************************************************/
#include <iostream>
using namespace std;
struct weather
{
float totalRain; // month's total amount of rain
float highTemp; // month's highest temperature
float lowTemp; // month's lowest temperature
float averageTemp; // month's average temperature
int highestMonth; // month with the highest temperature
int lowestMonth; // month with the lowest temperature
float averageRain; // average monthly rain
};
//Function Prototypes
void data(weather* get, int SIZE);
void calculate(const weather array[], int months, weather &annual);
int main()
{
// Initialize Variables
const int numMONTHS = 12;
weather monthly[numMONTHS];
weather annualy;
//Input
data(monthly, numMONTHS);
//Calculate Stats
calculate(monthly, numMONTHS, annualy);
//Output
cout << endl;
cout << "Average Monthly Rain: " << annualy.averageRain << endl;
cout << "Highest Temperature Month: " << annualy.highestMonth << endl;
cout << "Lowest Temperature Month: " << annualy.lowestMonth << endl;
return 0;
}
void data(weather* get, int SIZE)
{
for (int i = 0; i < SIZE; i++)
{
cout << "Enter total rain for month " << (i + 1) << ": ";
cin >> get[i].totalRain;
cout << endl;
cout << "Enter highest temperature for month " << (i + 1) << ": ";
cin >> get[i].highTemp;
cout << endl;
cout << "Enter lowest temperature for month " << (i + 1) << ": ";
cin >> get[i].lowTemp;
cout << endl;
get[i].averageTemp = (get[i].highTemp + get[i].lowTemp) / 2;
}
}
void calculate(const weather array[], int months, weather &annual)
{
annual.averageRain = 0;
annual.highestMonth = 0;
annual.lowestMonth = 0;
for (int i = 0; i < months; i++)
{
annual.averageRain += array[i].totalRain;
if (array[i].highTemp > array[annual.highestMonth].highTemp)
annual.highestMonth = i;
if (array[i].lowTemp > array[annual.lowestMonth].lowTemp)
annual.lowestMonth = i;
}
annual.averageRain /= months;
}