Please take a look at my function call. I don't know if I'm handling the return values right. It works for an employee with less than or equal to 40 hours worked, but the over time is paying 2.5 times instead of 1.5 times. Should I be using some kind of alias for handling the struct in the functionion calls and returns? thanks
#include <iostream>
#include <iomanip>
using namespace std;
struct worker {
int idNumber;
int hoursWorked;
double hourlyRate;
double earned;
};
[B]
worker [/B]inputData(int, int, double);[B]
worker calculatePay(worker);[/B]
void outputPay(worker);
const double OVERTIME_RATE = 1.5;
int main() {
int id, hrs, rate;
cout << "Enter employee ID number, hours worked, and pay rate: ";
cin >> id >> hrs >> rate;
[B] outputPay( calculatePay( inputData(id, hrs, rate) ) ); [/B]
return 0;
}
worker inputData(int number, int hrsWorked, double rate) {
worker w;
w.idNumber = number;
w.hoursWorked = hrsWorked;
w.hourlyRate = rate;
return w;
}
worker calculatePay(worker emp) {
double pay = static_cast<double>(emp.hoursWorked) * emp.hourlyRate
+ OVERTIME_RATE * emp.hourlyRate * static_cast<double>(emp.hoursWorked - 40);
emp.earned = pay;
return emp;
}
void outputPay(worker idNum) {
cout << endl << setw(10) << "employee" << setw(10) << "hours" << setw(10)
<< "rate" << setw(10) << "pay" << endl << endl;
cout << fixed << setprecision(2) << setw(10) << idNum.idNumber << setw(10) << idNum.hoursWorked << setw(10)
<< idNum.hourlyRate << setw(10) << idNum.earned << endl;
}
Enter employee ID number, hours worked, and pay rate: 12 41 10
employee hours rate pay
12 41 10.00 425.00