-1

I am trying to write a program to display an account balance each month and am having an issue getting 3 columns to justify correctly. The output expected should look like:

                 Total  
Month            Accumulated  
------           -----------  
2015 March            500.00  
2015 April           1001.13  
2015 May             1503.38  
2015 June            2006.76  
2015 July            2511.28

But my output is looking like this:

                 Total  
Month            Accumulated  
------           -----------  
2015 March            500.00  
2015 April            1001.13  
2015 May              1503.38  
2015 June             2006.76  
2015 July             2511.28

I need to have the digits line up evenly on the right. I can't seem to get it looking any closer to what I need using right justification. I'm hoping someone here might have a simple fix that I've somehow overlooked. Currently, this is how the line is written:

cout << setw(5) << left << currentYear << setw(18) << currentMonthName << totalAccum << endl;

Any suggestions would be greatly appreciated. Thanks!

Sarah Koch
  • 11
  • 4

1 Answers1

0

I figured it out - needed to add a " " that would act as a placeholder, THEN do the right justification:
cout << setw(5) << left << currentYear << setw(10) << currentMonthName << " " << right << setw(13) << totalAccum << endl;

Sarah Koch
  • 11
  • 4