/*
Name: Program 5; Payroll Version 1
Author: william
Status: Incomplete
[b]Issues:Only the first line prior to my timecard loop will execute. I can not execute the timecard loop. I am unable to store a first and last name in my struct array. Any assistance you can provide is greatly appreciated. Thank you.[/b]
Description: This program will process employee master information and payroll.
*/
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//Define struct for employee data
struct EmployeeMasterInfo
{
int employeeId;
string employeeName;
double payRate;
int typeOfEmp;
};
int main(int argc, char *argv[])
{
// variables to be used
const int NUM_EMPS = 4;
int index;
EmployeeMasterInfo empRecord[NUM_EMPS+1];
double grossPay;
double netPay;
int hoursWorked;
double overTimePay;
int overTimeHours;
double totalGrossPay;
const double TAXRATE = .15;
double taxOwed;
//Get employee data for master record
cout<<"Enter employee master data for "<< NUM_EMPS<<"employees.";
for (index = 0; index < NUM_EMPS; index++)
{
cout << "Enter information for emplyee #" << (index + 1)<<":\n";
cout << "Employee ID:";
cin >> empRecord[index].employeeId; //get employee id
if (empRecord[index].employeeId > 0) //verify user input
{
cout << "Employee Name:";
cin >> empRecord[index].employeeName;
cout << "Employee Pay rate:";
cin >> empRecord[index].payRate; //get employee payrate
if (empRecord[index].payRate > 0) //verify user input
{
cout << "Type:";
cin >> empRecord[index].typeOfEmp; //get employee classification type manager =1 or union =0
if ((empRecord[index].typeOfEmp = 1) || (empRecord[index].typeOfEmp = 0)) //verify user input
{
cout << "Employee master record is complete for employee " << (index + 1) <<".\n"; //successful record input message
}
else
{
cout << "Improper data entry; type should be 1 or 0./n"; //employee classification type error message
}
}
else
{
cout << "All dollar values must be positive integers.\n"; //Error message for negative pay rate entry
}
}
else
{
cout << "The employee ID number should be greater than 0.\n"; //Error message for negative interger employee id entry
}
}
//Timecard Processing
cout << "\nEnter timecard information for each employee:\n";
cout << fixed << showpoint << setprecision(2);
for (index = 0; index < NUM_EMPS; index++)
{
//Union timecard processing
if (empRecord[index].typeOfEmp = 0)
{
cout << "Enter hours worked for " << empRecord[index].employeeName << ":"; //get hours worked by each employee
cin >> hoursWorked;
if (hoursWorked > 40) //evaluate if overtime pay needs to be calculated
{
overTimeHours = hoursWorked - 40; //calculate overtime hours
if (overTimeHours > 0) //Validate overtime requirment for calculation
{
//Calculate total gross pay; overtime; taxes owed; net pay
grossPay = (hoursWorked - overTimeHours) * empRecord[index].payRate;
overTimePay = (empRecord[index].payRate + (empRecord[index].payRate / 2)) * overTimeHours;
totalGrossPay = grossPay + overTimePay;
taxOwed = totalGrossPay * TAXRATE;
netPay = totalGrossPay - taxOwed;
cout << " Payroll Report";
cout << "\n";
cout << "ID" << setw(15) << "Gross Pay" << setw(10) << "Tax" << setw(10)<< "Net Pay.\n";
cout << empRecord[index].employeeId << setw(15) << totalGrossPay << setw(10) << taxOwed << setw(10)<< netPay;
}
if (overTimeHours < 0) // no overtime required calculation for union
{
//Calculate total gross pay; taxes owed; net pay
totalGrossPay = hoursWorked * empRecord[index].payRate;
taxOwed = totalGrossPay * TAXRATE;
netPay = totalGrossPay - taxOwed;
cout << " Payroll Report";
cout << "\n";
cout << "ID" << setw(15) << "Gross Pay" << setw(10) << "Tax" << setw(10)<< "Net Pay.\n";
cout << empRecord[index].employeeId << setw(15) << totalGrossPay << setw(10) << taxOwed << setw(10)<< netPay;
}
}
//Mangement timecard processing
if (empRecord[index].typeOfEmp = 1)
{
cout << "Enter hours worked for " << empRecord[index].employeeName << ":";
cin >> hoursWorked;
if (hoursWorked > 40)
{
//calculate overtime pay
overTimeHours = hoursWorked - 40;
if (overTimeHours > 0)
{
grossPay = (hoursWorked - overTimeHours) * empRecord[index].payRate;
overTimePay = empRecord[index].payRate * overTimeHours;
totalGrossPay = grossPay + overTimePay;
taxOwed = totalGrossPay * TAXRATE;
netPay = totalGrossPay - taxOwed;
cout << " Payroll Report";
cout << "\n";
cout << "ID" << setw(15) << "Gross Pay" << setw(10) << "Tax" << setw(10)<< "Net Pay.\n";
cout << empRecord[index].employeeId << setw(15) << totalGrossPay << setw(10) << taxOwed << setw(10)<< netPay;
}
//calculation without overtime pay
if (overTimeHours < 0)
{
totalGrossPay = hoursWorked * empRecord[index].payRate;
taxOwed = totalGrossPay * TAXRATE;
netPay = totalGrossPay - taxOwed;
cout << " Payroll Report";
cout << "\n";
cout << "ID" << setw(15) << "Gross Pay" << setw(10) << "Tax" << setw(10)<< "Net Pay.\n";
cout << empRecord[index].employeeId << setw(15) << totalGrossPay << setw(10) << taxOwed << setw(10)<< netPay;
}
}
}
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
This post has been edited by no2pencil: 05 May 2012 - 05:23 PM
Reason for edit:: Corrected code tags

New Topic/Question
Reply




MultiQuote




|