I have a function that is supposed to return the sum of the first "n" integer squares. So with the argument n being 4, it is supposed to return the sum of the first 4 square integers which would be 30 because 1^2 + 2^2 + 3^2 + 4^2 = 30. The problem is is my function returns 5 for some reason. What is the problem with my code?
#include <iostream>
using namespace std;
int sum_of_squares(int n) {
int sum = 0;
for (int i = 0; i <= n; i++) {
i *= i;
sum += i;
}
return sum;
}
int main() {
cout << sum_of_squares(4) << endl;
}