C++ cout setw payroll data properly in dollars and cents
#include <iostream> using namespace std; #include <iomanip.h> int main()/*from w w w. j a va 2 s. co m*/ { char emp_name[ ] = "Mary"; char pay_date[ ] = "03/09/92"; int hours_worked = 43; float rate = 7.75; // Pay per hour float tax_rate = .32; // Tax percentage rate float gross_pay, taxes, net_pay; // Computes the pay amount. gross_pay = hours_worked * rate; taxes = tax_rate * gross_pay; net_pay = gross_pay - taxes; // Prints the results. cout << "As of: " << pay_date << "\n"; cout << emp_name << " worked " << hours_worked << " hours\n"; cout << "and got paid " << setw(2) << setprecision(2) << gross_pay << "\n"; cout << "After taxes of: " << setw(6) << setprecision(2) << taxes << "\n"; cout << "his take-home pay was $" << setw(8) << setprecision(2) << net_pay << "\n"; return 0; }