I just need a little advice. This code I have written works well. The only problem I am having is that the output is not lining up and I don't know what to do. If everything was entered line by line I could get it to line up. Since it is done through a for loop I don't know what to do to get them to line up in the output. Any help would be appreciated.
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
int avgRain[] = {1,2,3,4,5,6,7,8,9,10,11,12};
int actRain[] = {12,11,10,9,8,7,6,5,4,3,2,1};
string months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int x;
int total, total2;
cout << "Month" << setw(22) << " Average Rainfall" << setw(22) << " Actual Rainfall" << setw(22) << " Total Below Average" << setw(22) << " Total Above 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 << months[i] << setw(13) << avgRain[i] << setw(22) << actRain[i] << setw(18) << total << setw(18) << total2 << endl;
}
return 0;
}