### Displaying ".00"

Hello guys. I just had a quick question.

I've got a program that is supposed to display information about net pay, social security withheld, etc. and thus needs to show dollar amounts like "1.00" instead of just "1"

How do I do that? I've got it all working otherwise. Everything is declared as floats and all that.

Thanks
Last edited on
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293`` ``````#include #include using namespace std; float sscons = .08; float withcons = .10; int main() { float hrs; float rate; float gross; float netpay; float sstax, withtax; float grosstotal = 0; float sstotal = 0; float checktotal = 0; float withtotal = 0; float avggross; cout << "Enter hours worked (0 to quit): "; cin >> hrs; while (hrs > 0) { if (hrs > 40) { cout << "Enter pay rate: "; cin >> rate; cout << endl; gross = ((hrs-40) * rate * 1.5) + (40 * rate); sstax = gross * sscons; withtax = gross * withcons; netpay = gross - sstax - withtax; cout << setprecision (4) << "Gross pay: " << gross << endl << "SS Withheld: " << sstax << endl << "Withholding Tax: " << withtax << endl << "Net Pay: " << netpay << endl; checktotal+=1; grosstotal+=gross; sstotal+=sstax; withtotal+=withtax; cout << endl << "Enter hours worked (0 to quit): "; cin >> hrs; } else { cout << "Enter pay rate: "; cin >> rate; cout << endl; gross = hrs * rate; sstax = gross * sscons; withtax = gross * withcons; netpay = gross - sstax - withtax; cout << setprecision (4) << "Gross pay: " << gross << endl << "SS Withheld: " << sstax << endl << "Withholding Tax: " << withtax << endl << "Net Pay: " << netpay << endl; checktotal+=1; grosstotal+=gross; sstotal+=sstax; withtotal+=withtax; cout << endl << "Enter hours worked (0 to quit): "; cin >> hrs; } } avggross = grosstotal / checktotal; cout << endl << "TOTALS" << endl << endl << "Total Payroll: " << grosstotal << endl << "Number of Checks: " << checktotal << endl << "Average Paycheck: " << avggross << endl << endl << "Total SS withheld: " << sstotal << endl << "Total Withholding: " << withtotal << endl; return 0; } ``````

I put it in where that example made it look like it should go, but it didn't work.

I still see whole numbers without following decimals like .00.

Do you see what I did wrong?
You also need to use the fixed flag.

`cout << fixed << setprecision( 2 ) << 3.14159 << endl;`
Topic archived. No new replies allowed.