try putting this in at the beginning of the function
Code:
cout<<"In function sum(), b = "<< b << ", e = " << e << ". Values are: ";
for (int i = b; i < e; i++)
cout<<' ' <<a[i];
cout<<endl;
That should help you find out if you are getting any erronous data.
Oh and by the way: return a[0]; is wrong
Edit: After some testing I have found at least two logic errors in my code. While the structure is still correct I was adding 1 to numbers I shouldn't have.
I will tell you however that e isn't the index of the last number, its one past it. So the call would look something like:
Code:
int arr[] = { 1, 2, 3, 4, 5 };
int s = sum(arr, 0, 5);
you can do it where e is the last index but its actually more messy IMO.