I am wondering why the following program produces this error. I have tried on the online gdb compiler and it works fine. I have searched it online and some recommended to use vector instead of array, but i can't since i am required to use array here. Could anyone suggest some advices for my program in order for it to work?
I have to submit this program via VPL, in which it is run on linux and has a -pedantic errors flag.
The program will output the variance (var) from the user input.
#include <iostream>
using namespace std;
double jum(double arrayz[], int y) {
double total=0, jumlah;
for (int i=0; i<y; ++i) {
total+=arrayz[i];
}
jumlah = total/y;
return jumlah;
}
double rata2(double arrayz[], int y) {
double total=0,average;
for (int i=0; i<y; ++i) {
total+=arrayz[i];
}
average = total/y;
return average;
}
int main() {
double data,average,jumlah;
int y;
cin >> y;
double arrayz[y]={};
for (int i=0; i<y; ++i) {
cin >> data;
arrayz[i]=data;
}
average=rata2(arrayz, y);
for (int i=0; i<y; ++i) {
arrayz[i]=(arrayz[i]-average)*(arrayz[i]-average);
}
jumlah=jum(arrayz, y);
cout << "Variance : " << jumlah;
return 0;
}
Any answer will be deeply appreciated!