#include <iostream>
#include <iomanip>
#include <cctype>
#include <vector>
using namespace std;
void Clear_Screen(void);
void Flush(void);
int main()
{
bool notValid;
float x, annualRain = 0, avgRain, lowRain, highRain;
string month[12] = {" January :", " February :", " March :", " April :",
" May :", " June :", " July :", " August :",
" September :", " October :", " November :", " December :"
};
cout <<"Please enter the total rainfall for each month\n" << endl;
vector<float> rainForMonth;
vector<float>::iterator iter;
for(int i=0; i<12; i++)
{
do
{ //Validation for input
notValid=false;
cout <<"\nEnter rainfall for " << month[i] <<" ";
cin >> x;
if (x<0)
{
cout <<"Must be a positive number!\n";
notValid=true;
}
}while (notValid);
rainForMonth.push_back(x);
}
for(int i=0; i<rainForMonth.size(); i++)
{
annualRain = annualRain + rainForMonth.at(i);
}
Flush();
cout << "\n\n Press any key to display results" << endl;
getchar();
Clear_Screen();
cout << " Total rainfall for the year : " << annualRain << endl;
avgRain=(annualRain)/rainForMonth.size();
cout << " The average rainfall per month : " << avgRain << endl;
iter = min_element(rainForMonth.begin(), rainForMonth.end());
cout << " The least amount of rainfall : " << *iter << endl;
iter = max_element(rainForMonth.begin(), rainForMonth.end());
cout << " The most amount of rainfall : " << *iter << endl;
cout << "\n\n Thank you for using the program!" << endl;
Flush();
cout << "\n\n Press any key to exit" << endl;
getchar();
return 0;
}
void Clear_Screen(void)
{
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
void Flush(void)
{
int ch;
do
{
ch = getchar();
}
while (ch != EOF && ch != '\n');
clearerr(stdin);
}