Question on Multidimensional Arrays

Hello All,

I am in my first programming class, so I am a noob at this. I wouldn't say I struggle with the material, but when I reach the limitations of my knowledge it really puts the breaks on my ability to debug and edit my code so it will compile and run.

I am working on a lab for my comp class, and I chose to create a multidimensional array for it although my professor told me I did not need to.

I am reaching out to see if the community can help guide me through this error I keep getting.

I get the error
error C2664: 'void display_race_results(float [],float [])' : cannot convert argument 1 from 'float [8][8]' to 'float []' (on line #)92

And as much as I dislike posting code, the error occurs in this portion when I call the function in line 92:


display_race_results(chevy[][SIZE], ford[][SIZE]);


the function is written like this:

void display_race_results(float chevy[][SIZE], float ford[][SIZE])
{
int race_counter = 1;
float diff = 0.0f;

cout << endl;
cout << "RACE #: TEAM CHEVY: TEAM FORD: WINNER:" << endl;

for (int i = 0; i < NUMBER_OF_CARS; i++)
{
for (int c = 0; c < SIZE; c++)
{
if (chevy[i][c] < ford[i][c]) //means that chevy won
{
diff = ford[i][c] - chevy[i][c];

cout << endl;

cout << " " << race_counter << " " << chevy[i][c] << " sec " << ford[i][c] << " sec CHEVY WINS!";

race_counter++;

}
else if (chevy[i][c] > ford[i][c]) //means that ford won
{

diff = chevy[i][c] - ford[i][c];

cout << endl;

cout << " " << race_counter << " " << chevy[i][c] << " sec " << ford[i][c] << " sec FORD WINS!";

race_counter++;
}
}
}
}


(I apologize if this looks like a huge mess)

the arrays are defined by global variables:

const int SIZE = 8;
const int NUMBER_OF_CARS = 8;


float chevy[NUMBER_OF_CARS][SIZE] = { { 0.0f } };
float ford[NUMBER_OF_CARS][SIZE] = { { 0.0f } };


-I guess I do not understand the context for the error, because I was able to get everything to work 100% with the array
chevy[SIZE] = 0;


Any guidance would be greatly appreciated
For such a 2D array, you should make the function parameter type this way float[8][]

Aceix.
Since the error appears to have to do with how you are calling the function you need to show us how exactly you are trying to call this function. You need to show us the calling function. We need to see how you call the function and how the parameters used in the parameters are declared.


I think you're making this too complicated. Since the code in display_race_results assumes that it knows the exact dimensions, just pass them that way:
1
2
void display_race_results(float chevy[NUMBER_OF_CARS][SIZE],
                          float ford[NUMBER_OF_CARS][SIZE])

and the call should be
display_race_results(chevy, ford);
Topic archived. No new replies allowed.