Hello guys, I'm trying to get this employee class to work correctly and everything seems to be fine, up until the part comes where it should output all of the information (such as hours worked, hourly pay rate, gross pay, tax amount, and net pay). My program allows me to enter all of the information to do all of this, but then when the calculations are done something screws up and I am not sure what, so all of the numbers are crazy things like 3.05045e-306.
Anyway, I'd appreciate it if anyone could spare some time whenever they get a chance to possibly take a look at this jumble of code and see if anything stands out to you. You guys have always been very helpful, so thanks in advance.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const double TAXRATE = .30;
const int WEEKS = 52;
class Empl{
public:
string firstname[5], lastname [5], payment[5];
int employeeID[5], overtimehours[5];
double grosspay[5], taxamount[5], netpay[5], avggrosspay[5], overtimepay[5], hoursworked[5], hourlyrate[5], avgnetpay;
void label();
void user(int);
void taxAmount(int);
void netPay(int);
void sortnetPay();
void displayAwesome();
};
class Hourly: public Empl{
public:
void hourgrossPay(int);
void hourovertimePay(int);
void houruser(int);
};
class Salary: public Empl{
public:
double sal[5];
void salgrossPay(int);
void salovertimePay(int);
void saluser(int);
};
#include "employee2.h"
#include <iostream>
#include <stdio.h>
#include <ctype.h>
using namespace std;
void Empl::label(){
cout << setw(40) << "Employee Payroll" << endl;
cout << "ID" << setw(15) << "FIRST NAME" << setw(15) << "LAST NAME" << setw(15) << "HW" << setw(15) << "HR" << setw(15) << "GROSS" << setw(15) << "TAX" << setw(15) << "NET" << endl;
}
void Empl::user(int i){
cout << "Enter Employee's first name: ";
cin >> firstname[i];
cout << "Enter Employee's last name: ";
cin >> lastname[i];
cout << "Enter Employee ID: ";
cin >> employeeID[i];
cout << "Salary or Hourly: ";
cin >> payment[i];
}
void Hourly::houruser(int i){
cout << "Enter hours worked: ";
cin >> hoursworked[i];
cout << "Enter hourly rate: ";
cin >> hourlyrate[i];
}
void Salary::saluser(int i){
cout << "Enter salary: ";
cin >> sal[i];
cout << "Enter overtime hours: ";
cin >> overtimehours[i];
}
void Hourly::hourgrossPay(int i){
grosspay[i] = hoursworked[i] * hourlyrate[i];
}
void Salary::salgrossPay(int i){
grosspay[i] = sal[i] / 52 * WEEKS;
}
void Empl::taxAmount(int i){
taxamount[i] = grosspay[i] * TAXRATE;
}
void Hourly::hourovertimePay(int i){
overtimehours[i] = hoursworked[i] - 40;
if(overtimehours[i] >= 0)
overtimepay[i] = overtimehours[i] * hourlyrate[i] * 1.5;
else
overtimepay[i] = 0;
}
void Salary::salovertimePay(int i){
hourlyrate[i] = grosspay[i] / 40;
if(overtimehours[i] >= 0)
overtimepay[i] = overtimehours[i] * hourlyrate[i] * 1.5;
else
overtimepay[i] = 0;
}
void Empl::netPay(int i){
netpay[i] = grosspay[i] - taxamount[i] + overtimepay[i];
avgnetpay += netpay[i];
}
void Empl::sortnetPay(){
int hold;
for(int pass = 0; pass < 4; pass++){
for(int j = 0; j < 4; j++){
if(netpay[j] > netpay[j + 1]){
hold = netpay[j];
netpay[j] = netpay[j + 1];
netpay[j + 1] = hold;
}
}
}
}
void Empl::displayAwesome(){
for(int k = 0; k <= 4; k++)
cout << employeeID[k] << setw(15) << firstname[k] << setw(15) << lastname[k] << setw(15) << hoursworked[k] << setw(15) << hourlyrate[k] << setw(15) << grosspay[k] << setw(15) << taxamount[k] << setw(15) << netpay[k] << endl;
cout << "AVERAGE NET PAY: " << avgnetpay << endl;
}
#include "employee2.h"
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(){
Empl employees;
Hourly hours;
Salary salaries;
cout << "Please enter information for five employees.\n";
for(int i = 0; i <= 4; i++){
employees.user(i);
if(employees.payment[i] == "salary"){
salaries.saluser(i);
salaries.salgrossPay(i);
salaries.salovertimePay(i);
}
if(employees.payment[i] == "hourly"){
hours.houruser(i);
hours.hourgrossPay(i);
hours.hourovertimePay(i);
}
employees.taxAmount(i);
employees.netPay(i);
}
employees.avgnetpay /= 5;
employees.sortnetPay();
employees.label();
employees.displayAwesome();
return 0;
}