I want to return the average of the two dimensional array with a different array using a function, the program runs fine, but it returns a big negative number, how do i return the array or apply pointers to my function? where do i add the pointer to make it work?
I encounter this:
warning: passing argument 1 of 'returnAvg' makes pointer from integer without a cast [enabled by default]|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void returnAvg(int allTest[2][2],int students,int test);
int main ()
{
int students = 2, test = 2, i,j;
int allTest[students][test];
for(i=0;i<students;i++){
for(j=0;j<test;j++){
printf("Student [%d] test [%d] score was> ",i+1,j+1);
scanf("%d",&allTest[i][j]);
}
}
returnAvg(allTest[2][2],students,test);
return 0;
}
void returnAvg(int allTest[2][2],int students,int test){
int i,j;
int avg[students];
for(i=0;i<students;i++){
int sum = 0;
for(j=0;j<test;j++){
sum += (allTest[i][j]);
}
avg[i] = sum/test;
}
printf("the average is %d, %d", avg[0],avg[1]);
return;
}