I have two user defined arrays and am trying to sum all of their elements together. Here is the function I must adhere to. int sum_of_all (int data1 [size], int data2 [size], int values)
the two arrays values are defined by the user in this:
1 2 3 4 5 6 7 8 9 10
void input (int data [size], int values)
{
for (int index=1; index<=values; index++)
{
cout << "Enter value "<< index << ": ";
cin >> data[index];
}
cout << endl;
}
but I cannot figure out how the int sum_of_all function is intended to work.
here is my attempt:
1 2 3 4 5 6 7 8 9 10 11 12 13
int sum_of_all (int data1 [size], int data2 [size], int values)
{
int index;
int size;
int sum=0;
cout << "The total sum is: ";
for (index=1; index<=values; index++)
{
sum=data1[index]+data2[index];
}
cout << sum;
}
needless to say, this does not work as sum changes each time stepped through the loop.