Awesome Possum
Gross Amount: ................... $10000.00
Federal Tax: .................... $1500.00
State Tax: ...................... $350.00
Social Security Tax: ............ $575.00
Medicare/Medicaid Tax: .......... $275.00
Pension Plan: ................... $50.00
Health Insurance: ............... $75.00
Net Pay: ........................ $9675.00
For some reason, the right side is not right-justified. I'd like to know why. Plese help. Thank you.
It is because the 'width' flag only applies to the next object you output (which is the dollar-sign). There is no direct way to prefix a dollar-sign to a number, but you can create a simple manipulator object to do it for you with its own overloaded stream insertion operator:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
struct dollar
{
double number;
dollar( double number ): number( number ) { }
};
ostream& operator << ( ostream& outs, const dollar& d )
{
ostringstream ss;
ss.flags( outs.flags() );
ss.precision( outs.precision() );
ss << " $" << d.number;
outs << ss.str();
return outs;
}
Now to display a specific quantity as a dollar amount, use it thus: