Just trying to write a basic function that calculates the sum of n even numbers. Ex: n = 3 (2 + 4 + 6 = 12) -> Sum = 12. n = 4 (2 + 4 + 6 + 8 = 20) -> Sum = 20, etc. I also want to return the sum to the console. I'm currently getting an error on my n variable (expression preceding parentheses of apparent call must have (pointer-to-) function type)
Not too sure, what that exactly means. Any help would be greatly appreciated! Thanks in advance.
1 2 3 4 5 6
int sumOfEvenNumbers(int n) {
int sum = 0;
sum += n (n + 1);
return sum;
}
1 2 3 4
int main(){
int sum = sumOfEvenNumbers(3);
cout << "Sum: " << sum;
}