View Single Post
Old 12-07-2004, 01:10 PM   #4 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
This is code I have so far

I think I have this one figured out but now I can't figure out how to line up the output correctly since I have added the 2 new entries(Regular pay and Premium pay)?

Code:
// Program Documentation //////////////////////////////////////////////////////
//
// Project Name  : OVERTIME
//
// Source File   : overtime.cpp
//
// Programmed By : Shang Fields
//
// Last Revision : 12/6/2004
//
// Version Number: 0.1
//
// Program Description ////////////////////////////////////////////////////////
//
// This program
//
///////////////////////////////////////////////////////////////////////////////

// Include Files //////////////////////////////////////////////////////////////
   #include <iostream.h>
   #include <conio.h>
   #include <iomanip.h>
// Function Prototypes ////////////////////////////////////////////////////////

// Program Mainline ///////////////////////////////////////////////////////////

int main( )
{
   const double FEDERAL_TAX_RATE = .33;
   const double STATE_TAX_RATE = 0.06;
   const double MAX_HOURS = 1.5;
   const double OVERTIME = 40.0;

   char employeeNumber[64];
   char employeeName[64];
   double federalTax;
   double grossPay;
   double hoursWorked;
   double regularPay;
   double premiumPay;
   double netPay;
   double payRate;  //stores employee's pay rate as a real number
   double stateTax;


   //input data
   cout << "Enter employee number:";
   cin.getline( employeeNumber, sizeof( employeeNumber ));
   cout << "Enter employee name:";
   cin.getline( employeeName, sizeof( employeeName ));
   cout << "Enter pay rate:";
   cin >> payRate;
   cout << "Enter hours worked:";
   cin >> hoursWorked;

   //calculations
   grossPay = hoursWorked * payRate;
   federalTax = grossPay * FEDERAL_TAX_RATE;
   stateTax = grossPay * STATE_TAX_RATE;
   netPay = grossPay - federalTax + stateTax;

   // CalcPay computes wages from the employee's pay rate
// and the hours worked, taking overtime into account

   if ( hoursWorked > MAX_HOURS ) {
      grossPay = (MAX_HOURS * payRate) +        // Yes
                (hoursWorked - MAX_HOURS) * payRate * OVERTIME;
               }else{
                  grossPay = hoursWorked * payRate;               // No
   }//endif

   //output results
   cout.setf(ios::fixed,ios::floatfield);
   cout.precision( 2 ); //output 2 decimal places
   const int fw = 10;
   
   cout << "===============================================================================" << endl;
   cout << "Employee        Hours                                                          Federal  State" << endl;
   cout << "Number  Name   Worked   Pay Rate Regular pay Premium Pay Gross Pay  Net Pay      Tax    Tax" << endl;
   cout.setf(ios::left,ios::adjustfield);
   cout << setw(fw + 9) << employeeNumber;
   cout << setw(fw + 9) << employeeName;
   cout.setf(ios::right,ios::adjustfield);
   cout << setw(fw)<< hoursWorked;
   cout << setw(fw)<< payRate;
   cout << setw(fw)<< regularPay;
   cout << setw(fw)<< premiumPay;
   cout << setw(fw)<< grossPay;
   cout << setw(fw)<< netPay;
   cout << setw(fw)<< federalTax;
   cout << setw(fw)<< stateTax;
   cout << "" << endl;

   cout << "================================================================================" << endl;
   getch();
   return 0;
}//endmn

Last edited by Valmont; 12-08-2004 at 01:44 AM.
verdell32 is offline   Reply With Quote