How To Declare A Two Dimensional Array In A Function Prototype.

This is the start of my code for my two dimensional array program. We have to use a two dimensional array to make a gradebook.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

// Function Prototypes
void loadData(int [][]);
void calculateGrades(int [][]);
void printArray(int [][]);

int main()
{
const int ROW = 2;
const int COL = 7;
int gradebook[ROW][COL] = {0};
int size = 0;

loadData(gradebook);
printArray(gradebook);


return 0;
}

The error is under the comment function prototype. it has the second pair of [] in each function prototype underlined in red. The error I am getting is "An array may not have elements of this type." How do I declare the function prototypes in the top? I will be passing the sizes to the functions in my programs.
The compiler doesn't allow this because it doesn't not how to address the array.
In order to find an instance of a gradebook, the compiler needs to know the dimensions of the array.

Move the following lines before your function prototypes:
1
2
const int ROW = 2;
const int COL = 7;


Then change your function prototypes:
1
2
3
void loadData(int [ROW][COL]);
void calculateGrades(int [ROW][COL]);
void printArray(int [ROW][COL]);


PLEASE USE CODE TAGS (the <> formatting button) when posting code. It makes your code easier to read and it makes it easier to respond to your post.
Oh OK! Thank you! Sorry about the bad code format!

Topic archived. No new replies allowed.