1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
cout<<"Company Payroll Program"<<endl;
void getInput(int empID[],int hoursWorked[],int payRate[],int unionCode[],char payrollType[]);
{
int empID[4];
int hoursWorked[4];
int payRate[4];
int unionCode[4];
char payrollType[4];
int i;
for(i=0;i<5;i++){
cout << "Please enter employee ID ";
cin >> empID[i];
while( empID[i] >800 || empID[i] <100 )
{
cout << "Invalid entry. Please enter employee ID " << endl;//requests user input with error message when invalid # is entered
cin >> empID[i];//assigns input to a declared variable
}
cout<<endl;
cout << "Please enter payroll type ";
cin >> payrollType[i];
while ( payrollType[i] != 'h' && payrollType[i] != 'H')
{
cout << "Invalid entry. Please enter payroll type " << endl;//requests user input with error message when input isn't h/H
cin >> payrollType[i];//assigns input to a declared variable
}
cout<<endl;
cout << "Please enter total hours worked ";
cin >> hoursWorked[i];
while( hoursWorked[i] >60 || hoursWorked[i] <0 )
{
cout << "Invalid entry. Please enter hours worked " << endl;//requests user input with error message when hours entered aren't between 0 and 60
cin >> hoursWorked[i];//assigns input to a declared variable
}
cout<<endl;
cout << "Please enter pay rate ";
cin >> payRate[i];
while( payRate[i] >45.0 || payRate[i] <8.5 )
{
cout << "Invalid entry. Please enter pay rate " << endl;//requests user input with error message when pay rate isn't between 8.50 and 45.0
cin >> payRate[i];//assigns input to a declared variable
}
cout<<endl;
cout << "Please enter union code ";
cin >> unionCode[i];
while( unionCode[i] != 1 && unionCode[i] != 2 && unionCode[i] != 3 )
{
cout << "Invalid entry. Please enter union code " << endl;//requests user input with error message when code entered isn't 1,2 or 3
cin >> unionCode[i];//assigns input to a declared variable
}
cout<<endl;
}
}
void doCalculations(int hoursWorked[],int payRate[],int unionCode[],double regularPay[],double overtimePay[],double netPay[],double grossPay[],double stateTax[],double federalTax[],double totalTax[],int unionDues[]);
{
int empID[4];
int hoursWorked[4];
int payRate[4];
int unionCode[4];
double regularPay;
double overtimePay;
double grossPay;
double stateTax;
double federalTax;
double totalTax;
double netPay;
int unionDues;
int i;
for(i=0;i<5;i++){
if ( hoursWorked[i] > 40 ){
regularPay[i] = payRate[i] * hoursWorked[i];//regularPay formula
overtimePay[i] = 1.5 * payRate[i] * (hoursWorked[i] - 40);//overtimePay formula
grossPay[i] = regularPay[i] + overtimePay[i];//grossPay for employees working more than 40 hours formula
}
else if ( hoursWorked[i] <= 40 ){
grossPay[i] = payRate[i] * hoursWorked[i];//grossPay formula for employees working 40 or fewer hours
regularPay[i] = payRate[i] * hoursWorked[i];//regularPay formula
overtimePay[i] = 0;//no OT granted
}
if (grossPay[i] < 500)
stateTax[i] = 0.0;//if grossPay < 500, stateTax is 0
else if (grossPay[i] >= 1000)
stateTax[i] = grossPay[i] * 0.05;//if grossPay >=1000, tax at 5%
else
stateTax[i] = grossPay[i] * 0.03;//otherwise, tax at 3%
if (grossPay[i] < 500)
federalTax[i] = 0.0;//if grossPay < 500, federalTax is 0
else if (grossPay[i] >= 1000)
federalTax[i] = grossPay[i] * 0.07;//if grossPay >=1000, tax at 7%
else
federalTax[i] = grossPay[i] * 0.05;//otherwise, tax at 5%
totalTax[i] = stateTax[i] + federalTax[i];//totalTax formula
switch(unionCode[i]){//based on prior user input of unionCode, a preselected unionDues value is chosen
case 1: unionDues[i] = 15;
break;
case 2: unionDues[i] = 25;
break;
case 3: unionDues[i] = 35;
break;
}
netPay[i] = grossPay[i] - (totalTax[i] + unionDues[i]);//netPay formula
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
|