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....
#include <iostream>
#include <iomanip>
usingnamespace std;
int grade(int win[][7], int num);
int main(){
constint ROWS = 60;
constint 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;
}
}
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.