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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void printMonth(int month);
void table(double currRainfall[], double prevRainfall[]);
int main()
{
double rain[12];
double ave[12];
int count = 0;
cout << "\nEnter average monthly rain" << endl;
for (int i = 0; i < 12; i++)
{
printMonth(i);
cout << ": ";
cin >> ave[i];
}
int currMonth = inputInteger("\nEnter current month: ", 1, 12);
cout << "\nEnter monthly rain from last year" << endl;
for (int month = currMonth - 1; count < 12; month = (month + 1) % 12, count++)
{
printMonth(month);
cout << ": ";
cin >> rain[month];
}
cout << endl;
table(rain, ave);
return 0;
}
void printMonth(int month)
{
//switch (month)
//{
//case 0:
// cout << "Jan";
// break;
//case 1:
// cout << "Feb";
// break;
//case 2:
// cout << "Mar";
// break;
//case 3:
// cout << "Apr";
// break;
//case 4:
// cout << "May";
// break;
//case 5:
// cout << "Jun";
// break;
//case 6:
// cout << "Jul";
// break;
//case 7:
// cout << "Aug";
// break;
//case 8:
// cout << "Sept";
// break;
//case 9:
// cout << "Oct";
// break;
//case 10:
// cout << "Nov";
// break;
//case 11:
// cout << "Dec";
// break;
//}
}
void table(double currRain[], double prevRain[])
{
const string monthName[12] = { "January", "February", "March",
"April", "May", "June",
"July", "August", "September",
"October", "November", "December" };
cout << setw(5) << "Month"
<< setw(20) << "Current RF"
<< setw(15) << "Previous RF"
<< setw(15) << "Average RF"
<< setw(15) << "Change RF"
<< endl << left;
for (int i = 0; i < 70; i++)
{
cout << "=";
}
cout << endl;
for (int i = 0; i < 12; i++)
{
cout << setw(20) << monthName[i]
<< setw(15) << currRain[i]
<< setw(15) << prevRain[i]
<< setw(15) << (currRain[i] + prevRain[i]) / 2
<< setw(15) << currRain[i] - prevRain[1] << endl;
}
cout << endl;
}
|