passing a two-dimensional array through a function?


If my explanation isn't clear enough read #9
http://books.google.com/books?id=LUJbzQR7KnoC&pg=PA322&lpg=PA322&dq=0.3*grade1%09%2B%090.2%09*grade2%09%2B%090.2%09*%09grade3%09%2B%090.3+*%09grade4+c%2B%2B&source=bl&ots=1JL47t2dCP&sig=I_hioqOBa_T6DqkXznAGfziROFE&hl=en&sa=X&ei=wBVmT8PHFcazsgL408C2Dw&ved=0CC8Q6AEwAQ#v=onepage&q&f=false

Hello I am attempting to pass a two-dimensional array 60 rows by 7 columns through a function, the purpose of this program is to calculate student grades. In the first column of every row it should be numbered 1-60 example shown below
1
2
3
4
5
6
ect... all the way to 60..

the next 4 rows allow for a user input and the last 2 output totals

I have no idea what I am doing wrong and I don't really know where to start please help me....


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream> 
#include <iomanip>

using namespace std;

int grade(int win[][7], int num);

int main(){
const int ROWS = 60;
const int COLS = 7;
int table[ROWS][COLS];
int total = grade(table[ROWS][7], 7);


}

int grade(int win[][7], int num){
	int sum = 0;
	for(int i = 0; i<num;i++){
	sum+=win[i][7];

	return sum;
	}

}
Last edited on
If you have []s after your array, you are either declaring it, or accessing its elements. You don't want to do either on line 12. To pass table, just pass table.
On line 20 you're accessing [7]th element of an array that has 7 elements. Since indices start from 0, that is out of bounds.
On line 12 you pass 7 while you should pass 60. num is the number of rows. The number of columns is already specified on line 6.
Topic archived. No new replies allowed.