Well I am learning about recursion. The exercise is I have to code a recursive function named sumSquares that returns the sum of squares of the numbers from 0 to num.
I have most of my code done (or so I believe), but I can't seem to get the last part in. I can't seem to get the sum :/
edit :D
I was also testing out reference variables (just to get more experience with them). I think I got that part down.
I'd appreciate any tips in the right direction! Thanks.
close the feed if you are done, otherwise if you were working with decimals, may I suggest that you use a double instead of an integer.
You can also save space by compressing the code lines
EX:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
double firstNumber,sum;
double sumSquare(double firstDigit); ///recursive function prototype
int main()
{
cout<<"Enter a number: \n> ";
cin>>firstNumber;
cout<<endl;
sum=sumSquare(firstNumber);
cout << "Sum of the squares of number " << sum << std::endl;
return 0;}
double sumSquare(double firstDigit) ///recursive function
{
if (firstDigit == 1)///my base
return firstDigit;
elsereturn firstDigit * firstDigit + sumSquare(firstDigit - 1); ///call to sumSquare function
}