2014-02-24 37 views
-1
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; 
} 

错误,我不知道如何解决我的错误。C++与“主要表达

Error: expected primary-expression before 'employee'

,但除此之外,我真的不知道如何把一个构造函数嵌套结构。我也真的不知道如何与一个数组定义结构

* * *编辑

现在说

ERROR: undefined reference to 'PayRoll::PayRoll()'

+0

你想要那条线究竟做什么? – Brian

+0

您未通过实例。 – hofmeister

+0

我想创建一个使用数组结构值的函数 – user3345335

回答

1

传递变量作为函数参数,只需指定变量名:

GrossPay(employee); 
1
GrossPay(PayRoll employee[]);  //Problem is here. 

当作为函数参数传递时,只能使用变量名:

GrossPay(employee);