struct PayInfo
{
int hours;
double payRate;
};
struct PayRoll
{
PayRoll();
int empNumber;
string name;
double grossPay;
PayInfo pay;
};
void GrossPay(PayRoll employee[])
{
for (int i = 0; i < 3; i++)
{
employee[i].grossPay = employee[i].pay.hours *
employee[i].pay.payRate;
}
}
int main()
{
PayRoll employee[3];
for (int i = 0; i < 3; i++)
{
cout << "Enter the employee's number: " << endl;
cin >> employee[i].empNumber;
cout << "Enter the employee's name: " << endl;
cin.ignore();
getline(cin, employee[i].name);
cout << "How many hours did the employee work?" << endl;
cin >> employee[i].pay.hours;
cout << "What is the employee's hourly pay rate?" << endl;
cin >> employee[i].pay.payRate;
}
GrossPay(employee);
for (int j = 0; j < 3; j++)
{
cout << "Here is the employee's payroll data:\n";
cout << "name: " << employee[j].name << endl;
cout << "Number: " << employee[j].empNumber << endl;
cout << "hours worked: " << employee[j].pay.hours << endl;
cout << "Hourly pay rate: " << employee[j].pay.payRate << endl;
cout << fixed << showpoint << setprecision(2);
cout << "Gross Pay: $" << employee[j].grossPay << endl;
}
return 0;
}
I don't know how to fix the error I have.
Error: expected primary-expression before 'employee'
but besides that, I'm not really sure how to put a constructor in a nested structure. I am also not really sure how define the structure with an array
* * *EDIT
Now it says
ERROR: undefined reference to 'PayRoll::PayRoll()'
要将变量作为函数参数传递,只需指定变量名称:
GrossPay(employee);
GrossPay(PayRoll employee[]); //Problem is here.
当作为函数参数传递时,仅使用变量名:
GrossPay(employee);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.