Uses the shortcut floating-point width method. - C++ Language Basics

C++ examples for Language Basics:Console

Description

Uses the shortcut floating-point width method.

Demo Code

#include <iostream>
#include <iomanip>
using namespace std;

int main()//from ww  w  .j ava  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;
}

Result


Related Tutorials