I have to write a file that has 4 columns and an unspecified number of rows. It has to have 3 void functions, the first is a readgrades function with two parameters double grades [][4], and int n for the number of rows. This function prompts the user for three grades, and the grades are read into the first three columns using a for loop

The second function is calcavg that has the same two parameters . This one calculates the average , and places the average in the fourth column.

The last function is printarray, same two parameters. This one displays the contents of the 2 dimensional array a. This uses a for loop as well.

Finally the main calls the functions readgrades, calcavg and printarray.

Here is what I have so far, but i'm pretty lost on this. I'm getting weird answers and errors. If anyone can help me fix this i'd appreciate it. ps. she wants void functions for some reason.

Code:

#include <iostream.h>
void readgrades (int grade [][4], int n){
int i, j;
for (i=0;i<=n;i++){
for (j=0;j<3;j++){
cout <<"please enter a grade: ";
cin >> grade [i][j];
}
}
void calcavg (double a[][4], int n){
int i, j, sum=0;
double average;
for (i=0; i<=4; i++){
for (j=0; j<=3;j++){
sum=sum + a[i][j];
}
average = (double)sum/3;
average=a[i][4];
}
}
void printarray (double a[][4], int n)
int i, j;
for (i=0;i<=n;i++){
for (j=0:j<=4;j++){
cout <<a[i][j];
}
}
void main (){
int n;
cout <<"Enter number of students: ";
cin >>n;
int a= new int [n][4];
readgrades (a,n);
calcavg(a,n);
printarray(a,n);
cout<<endl;
}