I'm trying to return a struct array from two functions. I don't know what to say. Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
struct worker {
int idNumber;
int hoursWorked;
double hourlyRate;
double earned;
};
[B]???[/B] input();
[B]???[/B] calculateEarned(worker []);
void outputWorkers(worker []);
int overtimeWorkers(worker []);
const double OVERTIME_RATE = 1.5;
int main() {
outputWorkers(calculateEarned(input()));
return 0;
}
[B]???[/B] input() {
int a;
cout << "Enter number of workers: ";
cin >> a;
cout << endl;
[B]static worker w[a]; // is this right??[/B]
[B] return w;[/B]
}
[B]???[/B] calculateEarned(worker w[]) {
cout << "enter the ID numbers of the " << sizeof(w) << " workers: ";
for(int i = 0; i < sizeof(w); i++)
cin >> w[i].idNumber;
cout << endl << "enter the hours worked for the " << sizeof(w) << " workers: ";
for(int k = 0; k < sizeof(w); k++)
cin >> w[k].hoursWorked;
cout << endl << "enter the base pay for each of the " << sizeof(w) << " workers: ";
for(int a = 0; a < sizeof(w); a++)
cin >> w[a].hourlyRate;
return w;
}
void outputWorkers(worker w[]) {
cout << setw(10) << "worker" << setw(10) << "rate" << setw(10) << "hours" << setw(10) << "pay"
<< endl << endl;
for(int i = 0; i < sizeof(w); i++) {
if(w[i].hoursWorked > 40)
w[i].earned = static_cast<double>(w[i].hoursWorked - 40) * w[i].hourlyRate * OVERTIME_RATE
+ static_cast<double>(40) * w[i].hourlyRate;
else
w[i].earned = static_cast<double>(w[i].hoursWorked) * w[i].hourlyRate;
cout << fixed << setprecision(2)
<< setw(10) << w[i].idNumber
<< setw(10) << w[i].hourlyRate
<< setw(10) << w[i].hoursWorked
<< setw(10) << w[i].earned
<< endl;
}
}
int overtimeWorkers(worker w[]) {
int count;
for(int i = 0; i < sizeof(w); i++)
if(w[i].hoursWorked > 40)
count = i + 1;
return count;
}