Organizing varied numbers into columns

So I have a program that (finally) works, thanks to help from this site. My output is numbers (money) printed to the console. They are of varying length. I am wondering if there is a way to make them line up nicely. I am using setprecision and fixed to maintain two decimal places. I am also using setw to move the numbers to approximately the right position. But some numbers are longer than others and so each line doesn't line up. For example,
Employee ID     Gross      Tax W/H      Net Pay
101456         $131.40    $19.71     $111.69
100045         $1576.81    $968.76     $608.05
100321         $1116.25    $839.80     $276.45
101987         $654.04    $98.11     $555.93

This is my output, I would like the numbers to line up nicely despite their varying lengths, but haven't been able to find a way. Thanks for the help

Steve
Last edited on
You can use '\t' also, it'll indent spaces irrespective of the money length.

E.g.,

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace std;

int main()
{
    cout << "$100\t\t$500\t\t$10" << endl;
    cout << "$20\t\t$10000\t\t$600" << endl;

    return 0;
}


Will give you :

$100            $500            $10
$20             $10000          $600


I hope you've got the idea ;)
Awesome, that's what I was looking for, thanks.
Topic archived. No new replies allowed.