Need help. Thanks

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 #include <iostream>
using namespace 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;
}
cout<<"The average of the class is "<<c_average;
Thanks Repeater I made it to
cout<<"The average of the class is "<<c_average(x, size);

then I placed a return avg; below avg = sum/size;
Topic archived. No new replies allowed.