C++ examples for Language Basics:Console
Computes and prints payroll data properly in dollars and cents, setprecision and setw
#include <iostream> #include <iomanip> using namespace std; int main()//from w w w .jav a2 s. c o 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; }