[英]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;
}
我不知道如何解決我的錯誤。
錯誤:“員工”之前預期的主要表達
但是除此之外,我還不確定如何將構造函數放在嵌套結構中。 我也不太確定如何用數組定義結構
* * *編輯
現在說
錯誤:對“ PayRoll :: PayRoll()”的未定義引用
要將變量作為函數參數傳遞,只需指定變量名稱:
GrossPay(employee);
GrossPay(PayRoll employee[]); //Problem is here.
當作為函數參數傳遞時,僅使用變量名:
GrossPay(employee);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.