Okay so I was told to make a program to enter how many students then calculating its average using function with the array in it.
The problem with this is the answer is always 1.
Can someone help me? Thanks.
#include <iostream>
usingnamespace std;
double c_average (double x[], int size);
int main()
{
int size;
double average;
cout<<"Enter how many students: ";
cin>>size;
double x[size];
for(int o=0;o<size;o++){
cout<<"Enter Student's Grade: ";
cin>>x[o];
}
average=c_average(x, size);
cout<<"The average of the class is "<<c_average;
return 0;
}
double c_average (double y[], int size){
double avg; int i;
double sum = 0.00;
for (int i = 0;i<size;i++){
sum = sum + y[i];
}
avg = sum/size;
}