// Timothy Price				CS1A				Ch 7 Challenge 2
/*******************************************************************************
 * Calculate rainfall
 * 
 * This program receives a number of values for monthly rainfall, and calculates
 * an annual total, monthly average, and least and greatest.
 * 
 * Inputs:
 *  Rainfall for each month
 * 
 * Outputs:
 *  Annual rainfall
 *  Monthly average rainfall
 *  Least month
 *  Greatest month
 ******************************************************************************/

#include <iostream>
#include <cmath>		// for calculations
#include <iomanip>		// for fixed decimal points

using namespace std;

// established number of months
const int SIZE = 12;

int main() {
	
	// data dictionary
	double month[SIZE];		// array to gather each month's rainfall
	double annual;			// annual total
	double average;			// monthly average
	float greatest;			// month with greatest rainfall
	float least;			// month with least rainfall
	
	// loop to receive inputs
	for(int i = 0; i < SIZE; i++){
		cout << "Enter the total rainfall for the month: ";
		cin >> month[i];
		cout << month[i] << endl;
		
		// input validation
		if(month[i] <= 0){
			cout << "Please enter a positive number: ";
			cin >> month[i];
			cout << month[i] << endl;
		}
		
		// add each month value to annual total
		annual += month[i];
	}
	
	// set starting values for greatest and least
	greatest = month[0];
	least = month[0];
	
	// loop to determine greatest or least
	for(int i = 0; i < SIZE; i++){
		if(month[i] > greatest)
		greatest = month[i];
			else if(month[i] < least)
			least = month[i];
	}
	
	// calculate monthly average
	average = (annual / SIZE);
	
	// display results
	cout << fixed << setprecision(2);
	cout << "--------------- RESULTS ---------------" << endl;
	cout << "Annual total rainfall: " << annual << endl;
	cout << "Average monthly rainfall: " << average << endl;
	cout << "Greatest monthly rainfall: " << greatest << endl;
	cout << "Least monthly rainfall: " << least << endl;
	return 0;
}