//Xinnuo Wang CS1A chapter 5 , P.295, #10
//
/*******************************************************************************
*
* Compute average rainfall
*-------------------------------------------------------------------------------
* This program accepts data and compute the average rainfall over a period of
* years.
*
* computation is based on the formula:
* Average rainfall per month = total rainfall / (The number of years x 12)
*-------------------------------------------------------------------------------
* INPUT
* The number of years : The asked number of years
* The number of month : The number of that month
* Inches of rainfall in the month: The asked inches in that month
* OUTPUT
* Total inches : Total inches of rainfall
* Average rainfall per month : The average inches of rainfall per month
*******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
int numbOfMonth; //INPUT - The asked inches in that month
int numbOfYear; //INPUT
int numbOfYears; //INPUT - The asked number of years
double inchesInTheMonth; // INPUT - The asked inches in that month
double totalInches; //OUTPUT - Total inches of rainfall
double avePerMonth; // OUTPUT - The average inches of rainfall per month
cout <<"Enter time in years"<< endl;
cin>> numbOfYears;
//
//Input Validation
while(numbOfYears< 1)
{
cout<<"Invalid input"<<endl;
return 0;
}
//
//Initialization
numbOfYear = 0;
totalInches = 0;
//
//Process
while (numbOfYear<numbOfYears)
{
numbOfMonth = 0;
while(numbOfMonth < 12)
{
cout<< "The rainfall in month "<< numbOfMonth<<" is : "<<endl;
cin >> inchesInTheMonth;
numbOfMonth++;
totalInches+=inchesInTheMonth;
}
numbOfYear++;
}
avePerMonth = totalInches / (numbOfYears*12);
while (inchesInTheMonth< 0)
{
cout<< "Invalid Input" << endl;
return 0;
}
//
//Output Result
cout << "The number of monthes is: " << (numbOfYears*12)<< endl;
cout<< "The total inches of rainfall is: " << totalInches << endl;
cout <<"The average rainfall per month is: "<< avePerMonth << endl;
return 0;
}