[英]C++ Error with "primary expression
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()'
错误:对“ PayRoll :: PayRoll()”的未定义引用
要将变量作为函数参数传递,只需指定变量名称:
GrossPay(employee);
GrossPay(PayRoll employee[]); //Problem is here.
当作为函数参数传递时,仅使用变量名:
GrossPay(employee);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.