我不知道爲什麼這不會運行。我應該在工資陣列中存儲hours * payrate
,然後showResults
將此信息和cout
它。當我運行它,我得到的錯誤是低於C++通過函數傳遞數組
error LNK2019: unresolved external symbol "void __cdecl showResults(int * const,int,double * const,double * const,double * const)" ([email protected]@[email protected]) referenced in function
error LNK2019: unresolved external symbol "void __cdecl getEmployeeData(int * const,int,double * const,double * const,double * const)" ([email protected]@[email protected]) referenced in function `_main`
代碼:
#include <iomanip>
#include <iostream>
using namespace std;
void getEmployeeData(int[], int, double[], double[], double[]);
void showResults(int[], int, double[], double[], double[]);
int main()
{
const int ARRAY_SIZE = 7;
int empId[ARRAY_SIZE] = {565, 845, 452, 130, 789, 758, 877};
double hoursWorked[ARRAY_SIZE]; // Holds hours worked
double payrate[ARRAY_SIZE]; // Holds pay rate
double wages[ARRAY_SIZE]; // Holds wages
getEmployeeData(empId, ARRAY_SIZE, payrate, hoursWorked, wages);
showResults(empId, ARRAY_SIZE, payrate, hoursWorked, wages);
system("pause");
return 0;
}
void getEmployeedata(int nums[],int size,double pay[],double hours[],
double wages[])
{
//Hours worked and Pay rate
for(int index = 0; index < size; index++)
{
cout << "Enter number of hours worked by employee number "
<< nums[index] << ": ";
cin >> hours[index];
cout << "\nEnter hourly pay rate ";
cin >> pay[index];
wages[index] = hours[index] * pay[index];
}
}
void showResults(int nums[], int size, double pay, double hours, double wages[])
{
for(int index = 0; index < size; index++)
{
cout << "Employee Number Gross Wage " << endl
<< nums[index] << " " << wages[index];
}
}
C++標準庫提供了一組豐富的[容器類型](http://en.cppreference.com/w/cpp/container)。這些可以很容易地進入和退出功能。你應該使用這些而不是舊式的數組。 – moooeeeep 2013-04-06 18:26:06