I am trying to convert the ouput of this recursive function to double, but no matter what I try the output remains integer. Could someone please assist.
int main()
{
int x,y;
cout << "Please enter the low value of the range to add: " << endl;
cin >> x;
cout << "Please enter the high value of the range to add: " << endl;
cin >> y;
cout << "The sum of the range is: " << static_cast<double>(addRange(x,y)) << endl;
cin.get();//To keep console window open
cin.get();//To keep console window open
return 0;
}
double addRange(int x, int y)
{
if (x > y)
return (0);
else
return static_cast<double>(addRange(static_cast<double>(x) + 1,y)) + x;
}