How To Pass A Two Dimensional Array To A Function.

For my C++ class I have to write grade book program using a two dimensional array. The grade book will be 5 rows, and 7 columns. In the below code I am trying to pass the array to a function to load data into the array. I know how to write the function, but I left it blank until I figure out how to pass the array to the function. Also, my professor says we have to do it this way, so I have to load the data using this function.

My code:

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

// Function Prototypes
const int ROWS = 3;
const int COL = 7;

void loadData(int [ROWS][COL],int);
void calculateGrades(int [ROWS][COL], int);
void printArray(int [ROWS][COL], int);

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

loadData(gradebook, size);


return 0;
}

*** void loadData(int gradebook[ROW][COL], int size) ***
{

return;
}

When I try to build the program it has the ROW in the starred line at the bottom underlined in red. The stars are only there to show what line the error is in. The compiler says the error is:

1>c:\users\hp\documents\college files\c++\chapter 7 page 457 number 9\chapter 7 page 457 number 9\main.cpp(27): error C2065: 'ROW' : undeclared identifier

If it matters I am using Microsoft Visual Studio 2010.
1
2
3
// Function Prototypes (they're not, btw)
const int ROWS = 3;
const int COL = 7;
void loadData(int gradebook[ROW][COL], int size)

Simple typo - next time you'll find it yourself ;)
Last edited on
AHHHHHHHHHHHHHHHHHH.

Thank you!!!! Stupid typos!
Topic archived. No new replies allowed.