//Roman Lara Delgado CSC5 Chapter 7, P.444, #2
//
/*******************************************************************************
*
* Calculate Rainfall Statistics
*_______________________________________________________________________________
* This program calculates the total rainfall of a year, the average monthly
* rainfall, and determines the months with the highest and lowest rainfall of
* that year.
* ______________________________________________________________________________
* INPUT
* rainfall[MONTHS] : The amount of rainfall in a month
*
* OUTPUT
* totalYear : The total amount of rainfall in the year
* averageMonthly : The average monthly rainfall in the year
* highestMonthName : The month with the highest rainfall
* lowestMonthName : The month with the lowest rainfall
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main ()
{
/***************************************************************************
* CONSTANTS
* -------------------------------------------------------------------------
* MONTHS : number of months in a year
* ************************************************************************/
//Declare Program Constants
const int MONTHS = 12; //Number of months in a year
//Delcare Program Variables
float rainfall[MONTHS]; //INPUT - The amount of rainfall in a month
string nameMonth[MONTHS] = {"Jan.", "Feb.", "Mar.", "Apr.", "May ", "Jun.",
"Jul.", "Aug.", "Sep.", "Oct.", "Nov.",
"Dec."}; //Name of each month in the year
float totalYear; //OUTPUT - The total amount of rainfall in the year
float averageMonthly; //OUTPUT - The average monthly rainfall in the year
float highestMonth; //CALC - The month with the highest rainfall
float lowestMonth; //CALC - The month with the lowest rainfall
string highestMonthName; //OUTPUT - Month with highest rainfall.
string lowestMonthName; //OUTPUT - Month with lowest rainfall
//Input Rainfall for the Specified Month
for (int count = 0; count < MONTHS; count++)
{
cout << "Enter the amount of rainfall for " << nameMonth[count] << ": ";
cin >> rainfall[count];
cout << endl;
totalYear += rainfall[count];
}
//Calculate Average Monthly Rainfall
averageMonthly = totalYear / MONTHS;
highestMonthName = nameMonth[0];
highestMonth = rainfall[0];
//Determine Month with Most Rainfall
for (int count = 1; count < MONTHS; count++)
{
if (rainfall[count] > highestMonth)
{
highestMonth = rainfall[count];
highestMonthName = nameMonth[count];
}
}
lowestMonthName = nameMonth[0];
lowestMonth = rainfall[0];
//Determine Month with Least Rainfall
for (int count = 1; count < MONTHS; count++)
{
if (rainfall[count] < lowestMonth)
{
lowestMonth = rainfall[count];
lowestMonthName = nameMonth[count];
}
}
//Output Rainfall Statistics
cout << fixed << setprecision(2) << endl;
cout << "The total rainfall of the year was: " << totalYear;
cout << " inches" << endl;
cout << "The monthly average rainfall was: " << averageMonthly;
cout << " inches" << endl;
cout << "The month with the most rainfall was " << highestMonthName;
cout << " with a rainfall of: " << highestMonth << " inches"<< endl;
cout << "The month with the least rainfall was " << lowestMonthName;
cout << " with a rainfall of: " << lowestMonth << " inches" << endl;
return 0;
}