Payroll program accumulation and processing employees
Feb 20, 2013 at 6:46pm Feb 20, 2013 at 6:46pm UTC
My teacher is awful and we pretty much have a terrible book and some links he gave us. Doesn't help out or anything so I'm doing this on my own. I need some insight because I can't figure this one out.
I have a complete working program, but I need to integrate these things:
total number of employees processed
total gross pay
highest gross pay and the employee id
lowest gross pay and the employee id
average gross pay
It is not arrays as we have not gone that far and it is for another assignment.
I am thinking I have to use counters (++i or i++?) to do it and access the information but after hours and hours of research I am lost.
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
#include <iostream> //allows program to output data to the screen
#include <iomanip>
using namespace std;
//function main begins the payroll calculation program execution
int main()
{
while (true ) { //This repeats the program. You close console window manually by clicking "x".
system ("CLS" ); //this will clear the screen of any text from prior run
std::cin.clear(); //this will clear any values remain in cin from prior run
std::cout << "Welcome to gmsd's Payroll Calculator!\n\n" ;
// variable declarations
int employeeID; // employee's ID number
double hoursWorked; // number of hours employee worked
float regularPay; // if hoursWorked <=40 then regular pay = hoursWorked * payRate
double overtimePay; // if hoursWorked >40 then over times pay = 1.5 * (hoursWorked - 40) * payRate
double federalTax; // amount of tax employee pays based on grossPay
double payRate; // employee's pay rate
double unionDues; // dues paid based on unionCode
double grossPay; // gross pay is hoursWorked times payRate
double netPay; // netPay is grossPay - (grossPay * federalTax)
double paidTax; // paidTax is grossPay - netPay
char unionCode; // employee's one character union code
char A = 'A' ; // unionCode A
char B = 'B' ; //unionCode B
char C = 'C' ; //unionCode C
for (int x = 1; x <=5; x++) // loop program 5 times
{
std::cout << "\nEmployeeID: " ; //request user input for EmployeeID
std::cin >> employeeID; // read input from user into employeeID
std::cout << "\nHours worked: " ; // request user input for hoursWorked
std::cin >> hoursWorked; // read input from user into hoursWorked
while (hoursWorked <0 || hoursWorked > 60) // only allow input from 0-60
{
std::cout << "\nError! You must enter a value between 0 and 60\n" ;
std::cout << "\nHours worked: " ;
std::cin >> hoursWorked;
}
std::cout << "\nPay rate: " ; // request user input for payRate
std::cin >> payRate; // read input from user into payrate
while (payRate <7.50 || payRate > 45.00) //only allow input from 7.50 - 45.00
{
std::cout << "\nError! You must enter a value between 7.50 and 45.00\n" ;
std::cout << "\nPay rate: " ;
std::cin >> payRate;
}
std::cout << "\nUnion code A, B, or C? " ; // request user input for unionCode
std::cin >> unionCode; // read input from user into unionCode
while (unionCode !=A && unionCode !=B && unionCode !=C) //only allow input A, B, or C
{
std::cout << "\nError! Your code must be A, B, or C\n" ;
std::cout << "\nUnion code: " ;
std::cin >> unionCode;
}
regularPay = hoursWorked * payRate; // calculate regularPay
overtimePay = 1.5 * (hoursWorked - 40) * payRate; // calculate overtimePay
// qualifier for regularPay
if (hoursWorked <= 40)
regularPay = hoursWorked * payRate;
overtimePay = 0;
// qualifier for overtimePay
if (hoursWorked > 40)
regularPay = payRate * 40;
overtimePay = (1.5 * payRate) * (hoursWorked - 40);
// calculate unionDues
switch (unionCode)
{
case 'A' : unionDues = 25;
break ;
case 'B' : unionDues = 50;
break ;
case 'C' : unionDues = 75;
break ;
}
grossPay = regularPay + overtimePay; // calculate grossPay
// qualifier for federalTax
if ( grossPay > 2000 ) federalTax = .25;
else if ( grossPay >= 1000 ) federalTax = .15;
else federalTax = .1;
netPay = grossPay - (grossPay * federalTax) - unionDues; // calculate netPay
paidTax = grossPay * federalTax; // calculate paidTax
std::cout << "\nIdentification Number: " << employeeID; //display employeeID
std::cout << "\nHours Worked: " << hoursWorked; //display hoursWorked
std::cout << "\nPay Rate: " << payRate; //display payRate
std::cout << "\nUnion Code: " << unionCode; //display unionCode
std::cout << fixed << setprecision(2); //format output to 2 decimal places
std::cout << "\nRegular Pay: " << regularPay; //display regularPay
std::cout << "\nOvertime Pay: " << overtimePay; // display overtimePay
std::cout << "\nGross Pay: " << grossPay; // display grossPay
std::cout << "\nFederal Tax: " << paidTax; // display federalTax
std::cout << "\nUnion Dues: " << unionDues; // display unionDues
std::cout << "\nNet Pay: " << netPay; // display netPay
std::cout << "\n" ;
}
std::cout << "\n\nBest payroll calculator in the whole world\n\n\n" ; // Termination message
system("PAUSE" );
}
return 0;
}
//end function main
Topic archived. No new replies allowed.