C++ cout setprecision set floating-point width method

Description

C++ cout setprecision set floating-point width method

#include <iostream>
using namespace std;
#include <iomanip.h>
int main()//  w w  w  . ja v a 2  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 " << setprecision(2) << gross_pay << "\n";
   cout << "After taxes of: " << setprecision(2) << taxes << "\n";
   cout << "his take-home pay was " << setprecision(2) << net_pay << "\n";
   return 0;
}



PreviousNext

Related