I'm having a hard time aligning decimal values. I am pretty sure its a combination of right alignment and setprecision/fixed but it doesn't seem to be working. I know other questions have been asked on the topic but I haven't found a clear solution to getting a bunch of columns (unique cout statements to align).
This is a chunk of my code:
double total_collect, sales, country_tax, state_tax, total_tax;
const double STATE_TAX_RATE = 0.04, COUNTRY_TAX_RATE = 0.02;
// Compute taxes
total_collect = 100;
sales = 100 / 1.06 ;
country_tax = sales * COUNTRY_TAX_RATE;
state_tax = sales * STATE_TAX_RATE;
total_tax = country_tax + state_tax;
//Display
cout << setiosflags(std::ios::right) ;
cout << "Totla Collected: " << setw(7) << "$ " << fixed << setprecision(2) << right << total_collect << endl;
cout << "Sales: " << setw(17) << "$ " << fixed << setprecision(2) << right << sales << endl;
cout << "Country Sales Tax: " << setw(5) << "$ " << fixed << setprecision(2) << right << country_tax << endl;
cout << "State Sales Tax: " << setw(7) << "$ " << fixed << setprecision(2) << right << state_tax << endl;
cout << "Total Sales Tax: " << setw(7) << "$ " << fixed << setprecision(2) << left << total_tax << endl << endl;
This is what it looks like:
This is what I would like it too like: