Hi guys, writing a code where the use inputs the 10 elements of the array and I have to write a function that gets the sum of the 10 elements. I can't really tell what I'm doing wrong. Here is my code:
void display(int a[], int s)
{
for (int i = 0; i < s; i++){
cout << a[i] << endl;
a[i] = -1; //problem here
}
}
You set each array element to -1 just before the call to stats (arr, A_SIZE, sum);
That's why it calculates the sum wrong because all elements are actually -1 and not the values inserted by the user.