Passing an array
I'm trying to use a multidimensional array but I am getting an error in the main. Am I passing the array correctly? Is there a reason why the second index (column index) and the first index (row index) is not used when passing an array?
// function prototype
double totalSalespersonSales( int [ ], [ salespeople ] , int );
// main
totalSalespersonSales( sales[ ] [ salespersonIndex ], products )
// function definition
double totalSalespersonSales( int setOfSalesPerSalesperson[ ] [ salespeople ], int salespersonIndex, int items )
{
int salespersonSalesTotal = 0;
for( int productIndex = 0; productIndex < items; productIndex++ )
{
salespersonSalesTotal += setOfSalesPerSalesperson[ productIndex ] [ salespersonIndex ];
}
return static_cast< double > ( salespersonSalesTotal );
}
[908 byte] By [
ericelysia] at [2007-11-11 10:31:11]

# 1 Re: Passing an array
Looks to me that:
// function prototype
double totalSalespersonSales( int [ ], [ salespeople ] , int );
should be
// function prototype
double totalSalespersonSales( int [ ][ ], int );
(leave out the comma between bracket pairs)
ALSO
when you pass an array you pass by its name - which is a reference to the memory location of its first element - and not as "name[]".
In order for your main procedure to pass an array to the totalSalespersonSales procedure that array needs to be declared and initialized. You also need to declare and initialize the values used as arguments to the procedure. The program doesn't know what you're thinking or what you want unless you tell it.
nspils at 2007-11-11 20:58:35 >
