The result of this question, it should have a payroll record consists all of these things. But i have a problem in calculating the TOTAL GROSS PAY FOR ALL EMPLOYEES by using arrays in struct (C++) but I am stuck. The total gross pay should be printed at bottom of the payroll record. I feel like something is missing in my coding but I can`t figure out what that thing is. I only have a problem in finding the total gross pay, others are okay.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double gross[10];
double sum = 0.0;
double totalGrossPay;
struct GrossPay {
int empID;
string empName;
double chargeHour;
int workingHours;
double grossPay;
};
GrossPay employee[10];
for (int i = 0; i < 10; i++) {
cout << (i + 1) << "."
<< "Employee Name :";
cin >> employee[i].empName;
cout << "Employee ID :";
cin >> employee[i].empID;
cout << "Employee`s charge rate per hour :";
cin >> employee[i].chargeHour;
cout << "Working hours :";
cin >> employee[i].workingHours;
cout << endl;
}
cout << "Employee ID\t"
<< "Employee Name\t"
<< "Gross Pay(RM)" << endl;
for (int i = 0; i < 10; i++) {
double gross = employee[i].chargeHour * employee[i].workingHours;
cout << employee[i].empID << "\t\t" << employee[i].empName << "\t\t" << gross;
cout << endl;
}
cout << endl;
for (int i = 0; i < 10; i++) {
totalGrossPay = sum + gross[i];
}
cout << "Total gross pay of 10 employees : RM" << totalGrossPay;
return 0;
}