program malfunction

Ok I have a program that has a 2 dimensional array in it. It compiles but I cant seem to get the right value in the final row of the array. It keeps coming out to 0 when its suppose to be an average and I cant seem to figure out how to fix it. Any advice would be appreciated.

here is the program:

#include <cstring>
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
using namespace std;

void funct(int sum[5],int array[6][5],int courses,int grade);
int main(){
int grade,courses,i=0, array[6][5],sum[5];
cout << "Imput how many grades and how many courses your going to imput" << endl;
cin >> grade >> courses;

while(i < courses){
cout << "Enter your grades for course "<< i+1 << endl;
for(int t = 0; t < grade; t++){
cin >> array[t][i];
sum[i] = array[t][i] + sum[i];
}
i++;}
funct(sum,array,courses,grade);

cout <<"the following are your grades, the final number is your average for that course" << endl;
for(int i = 0; i < courses; i++){
cout << "course " << i+1 << endl;
for(int t=0; t <= grade; t++){
cout << array[t][i] << ",";
}
cout << endl;
}}
void funct(int sum[5],int array[6][5],int courses,int grade){
int i=0,x;

while ( i < courses){
array[grade+1][i] = sum[i]/courses;
i++;
}}


btw I'm new here so HEY EVERYONE :D
Last edited on

sum[5] is not initialized.

instead of
array[grade+1][i] = sum[i]/courses;

do

array[grade][i] = sum[i]/courses;

You may get something.
omg thank you so much. it works now
Topic archived. No new replies allowed.