Hi all,
I'm struggling to understand the secret behind passing a multidimensional array to a function in my program, please see my code below:
Code:
#include <iostream>
using namespace std;
const int employees = 4;
const int items = 5;
int validateEmployeeNumber(); // enure only numbers within the acceptable range are passed
void zeroArray( int[][items], int ); // wipe all data from the array
int main()
{
int sales[employees][items];
int employeeNumber = 0;
zeroArray( sales[][items], employees);
while ( employeeNumber != -1 )
{
employeeNumber = validateEmployeeNumber();
}
} // end main
// wipe all data from the array
void zeroArray( int sales[][items], int employees )
{
for ( int i = 0; i < employees; i++ )
{
for ( int j = 0; j < items; j++ )
{
sales[i][j] = 0;
}
}
} // end function zeroArray
// enure only numbers within the acceptable range are passed
int validateEmployeeNumber()
{
int empNo;
cout << "Enter employee number ( or 0 to show summary ): ";
cin >> empNo;
while ( empNo < 0 || empNo > 4 )
{
cout << "Your input was not recognised!\nEnter employee number ( or 0 to show summary ): ";
cin >> empNo;
}
return empNo - 1;
} // end function validateEmployeeNumber
My program refuses to work even though I've followed the textbook instructions and explicitly specified the second dimension's array boundaries!
My IDE keeps telling me "Line 15 - error: expected primary-expression before ‘]’ token"
Any help on this issue would be most appreciated!