My program is supposed to calculate the sum of all the squares of numbers up until the users input. For example if the user inputs 2, the function will perform : (1^2 + 2^2) However my program refuses to do anything when run. (Not sure if this is a function problem, or with the main body.)
#include <iostream>
#include <cmath>
using namespace std;
int sumofsquares (int num)
{
int i;
int answer;
for(int i=0; i <= num; i++){
answer = (num * num)+ num;
}
return (answer);
}
int main(){
int num;
cout<< "Enter a number" <<endl;
cin >> num;
while( num != -1){
sumofsquares(num);
}
cout<< "The sum of squares is "<< num <<endl;
return 0;
}