//Jonathan Estrada CSC5 Chapter 7, P.444, #2
/*******************************************************************************
* COMPUTE RAINFALL
* _____________________________________________________________________________
* This program asks user for rain fall for each month but not accepting invalid
* for all 12 months in the year. The total rainfall for the year is acumulated
* and then used to compute the monthly average. By the end the program will
* display which month had the most and least rainfall throughout the year.
* _____________________________________________________________________________
* INPUT
* rainfall : number of months and number of inputs
*
* OUTPUT
* totalRainAmmount : accumulated rain fall
* monthlyavgRainfall : calucated average monthly rainfall
* highest : highest rainfall
* lowest : lowest rainfall
*
* *****************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double rainfall[12];
float totalRainAmmount;
float monthlyavgRainFall;
float highest;
float lowest;
cout << "Please enter monthly rainfall for each month," << endl << endl;
for(int i = 0; i < 12; i++)
{
cout << "Enter rainfall for month #" << (i+1) << ":";
cin >> rainfall[i];
cout << rainfall[i] << endl;
while(rainfall[i] < 0)
{
cout << "Invalid cannot be negative Please enter rainfall for "
<< "month #" << (i+1) << ":";
cin >> rainfall[i];
cout << rainfall[i] << endl;
}
}
for(int i = 0; i < 12; i++)
{
totalRainAmmount += rainfall[i];
}
highest = rainfall[0];
lowest = rainfall[0];
for(int i = 0; i < 12; i++)
{
if(rainfall[i] < lowest)
lowest = rainfall[i];
if(rainfall[i] > highest)
highest = rainfall[i];
}
monthlyavgRainFall = totalRainAmmount / 12;
cout << fixed << setprecision(2);
cout << "The average Monthly Rain Fall is " << monthlyavgRainFall
<< ", the total rain ammount for the year is " << totalRainAmmount
<< " and the highest rainfall was "<< highest << " and "
<< "the lowest was " << lowest << "." << endl;
return 0;
}