0

Hi, I'm having trouble getting my summation function to work using recursion.

I am reading in a set of 10 numbers from a file into an array, then printing the array out using recursion, then I have to take the summation of 1-last number in the array (Ex 1-14).

The problem is that my function currently sums all of the elements in the array( 3, 4, 34, 43, 12, 14, etc), instead of 1-14. Any help?

NOTE: This is partial code.

```
// main
int main(){
const int length = 10;
int Array[length];
first = &Array[0];
last = &Array[length -1]; //14 is last element in this case.
sum = sumOfInt(last);
cout << "SUM of numbers until " << *last << ": " << sum << endl << endl;
return 0;
}
//Summation recursion function
int sumOfInt(int *n)
{
int sum;
if (*n > 0)
{
sum = *n + sumOfInt(n - 1);
return sum;
}
}
```