Hi folks. I am looking for a way to control precisely where the output of a cout statement appears, and setw just isn't doing it for me. Here's the synopsis of the program:
It's a payroll program (fairly popular in C++ courses so the searches tell me) that calculates the numbers for various employees given pay, hours worked, hourly wage, etc, and then outputs it. I have all of that working fine and dandy.. save for the fact the output is ugly something harsh.
Employee Hourly Hours Tax Gross Net
Name Rate Worked Rate Amount Amount
John Smith 10.45 40.00 15.00 418.00 390.13
Jane Doe 12.50 45.00 15.00 656.25 612.50
Harry Morgan 20.00 40.00 20.00 800.00 760.00
Carmen Martinez 25.00 35.00 25.00 875.00 840.00
Jacintha Washington 50.85 60.00 35.00 4576.50 4445.74
50.85 60.00 35.00 4576.50 4445.74
Total gross amount: 11902.25
Total net amount: 11494.12 |
As you can see, works fine and dandy for the first line of output, but from there it's a really ugly snowball effect because of the name lengths and varying output and such.
If you'd like a quick laugh, here's what I've been working with so far:
1 2 3 4 5 6
|
cout << employeeName;
cout << setprecision(2) << fixed << showpoint << setw(17) << hourlyRate;
cout << setprecision(2) << fixed << showpoint << setw(11) << hoursWorked;
cout << setprecision(2) << fixed << showpoint << setw(11) << taxRate;
cout << setprecision(2) << fixed << showpoint << setw(10) << grossAmount;
cout << setprecision(2) << fixed << showpoint << setw(10) << netAmount << endl;
|
Square wheel, amirite? I just know there's a way to do what I am looking for, to clean up that nasty output and put all the results right beneath the header at the top of the column, but all of my searching has yielded not, so here I am. Advice?
Any help would be appreciated!
- Ghostwish