// ALEEF HYQAL BIN HILMERIZA   A18CS0023	SECTION 11
// CHENG SHIN WEI			   A18CS0046	SECTION 11

#include <iostream>
#include<iomanip>
using namespace std;

int main()
{
	// month   : number of month in year
	// totalRf : total rainfall for the given periods
	// TM	   : total months within the given periods
	// Y 	   : to hold the counter for outer loop (year)
	// M       : to hold the counter for inner loop (month)
	
	int month =12, TM = 0, years, M, Y=0;
	double AVG, totalRF = 0, rainfall;	
	
	cout << "Please enter the number of years: ";
	cin >> years;
	TM = years*month;	
	
	if (years > 0)
	{
		do
		{
			Y++;
			cout << endl;
			for (M = 1; M <= 12; M++)
			{
				cout << "Please enter the inches rainfall for year "
				<< Y << " month " << M << ": ";
				cin  >> rainfall;
				
				if (rainfall >= 0)
				{
					totalRF+=rainfall;
				}
				else
				{
					cout << "Rainfall must be positive value" << endl;
					M--;	
					continue;	
				}	
					
			}
			
		} while ( Y < years);
		
		cout << endl;
		cout << "The total numbe of months is " << TM << endl;
		cout << "The total inches of rainfall is " << totalRF << endl;
		
		AVG = totalRF/TM;
		cout << setprecision(4) << fixed << showpoint;
		cout << "The total average rain-fall over a period of years in Johor Bahru is "
		<< AVG;	
		
	}
	else
	 	cout << "Invalid input and try again!";
	
	 return 0;	
}
