1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
double rain, total=0, average;
int years, inputRainAmount;
bool inputFail;
const string MONTHS_NAMES [] = {"Jan" , "Feb", "Mar", "Apr","May",
"Jun","Jul","Aug", "Sep", "Oct", "Nov", "Dec"};
do {
cout << "Please enter the amount of years: ";
cin >> years;
inputFail = cin.fail() || years <=0;
if (inputFail==true)
{
cout << "Error: number of years must be >0" << endl;
cin.clear();
cin.ignore(INT_MAX, '\n');
}
} while (inputFail);
for (int i = 1; i <=years; i++)
{
cout << "\nStarting year number " << i << endl;
for (int j = 0; j <= 11; j++)
{
cout << "\nEnter amount of rain for " << MONTHS_NAMES[j]<< ":" ;
//input validation
cin >> inputRainAmount;
total += rain;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
|