Reputation: 13
problem is in inner for loop
for (int i=0, j=0; i<n; i++, j++){
if (i != j){
cout << sum = sum + arr[j] <<endl;
*//error: overloaded function type*
}
}
cout << sum = sum + arr[j] <<endl;
Upvotes: 0
Views: 120
Reputation: 63471
This is a problem with operator precedence.
It can be resolved by putting the expression in parentheses:
cout << (sum = sum + arr[j]) << endl;
However, this is pretty horrible style, and you should split it into two lines instead:
sum += arr[j];
cout << sum << endl;
Your future self, and anyone else who reads your code, will thank you.
Upvotes: 4