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
|
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
double avgRain[] = {1.81, 1.04, 0.27, 7.25, 7.79, 2.88, 9.71, 5.04, 3.59, 8.80, 3.67, 2.07};
double actRain[] = {9.57, 4.42, 4.78, 3.14, 8.72, 3.24, 6.01, 6.31, 9.76, 6.10, 8.37, 6.29};
string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int total, total2;
cout << "Month" << setw(18) << " Average" << setw(11) << " Actual" << setw(16) << " Total Below" << setw(13) << " Total Above" << endl;
cout << setw(23) << "Rainfall" << setw(12) << "Rainfall" << setw(13) << " Average" << setw(12) << " Average" << endl << endl;
for (int i = 0; i < 12; i++)
{
total = avgRain[i] - actRain[i];
total2 = actRain[i] - avgRain[i];
//cout << total;
if( total < 0 )
{
total = 0;
//cout << total;
}
if ( total2 < 0)
{
total2 = 0;
//cout << total2;
}
cout << setw(11) << left << months[i] << setw(11) << right << avgRain[i] << setw(11)
<< actRain[i] << setw(11) << total << setw(15) << total2 << endl;
}
return 0;
}
|