I am trying to calculate the sum of the series below (line 3). This is what I've come up with. I tried compiling and running it but there is a compile time error "[Error] ld returned 1 exit status". I'm unable to figure out why. Can anybody please help me? Thanks in advance.
/* FUNCTION TO PERFORM THE SUM OF THE FOLLOWING SERIES
x - x^2/3! + x^3/5! - ..... upto n terms */
#include <iostream>
double sumseries(double x, int n);
usingnamespace std;
int main()
{
int n;
double x;
cout<<"\nEnter the value of 'x' \n";
cin>>x;
cout<<"\nEnter the number of terms\n";
cin>>n;
double result = sumseries(x,n);
cout<<"\nThe result is "<<result;
return 0;
}
double sumseries(double x, int n)
{
double sumo = 0.0, sume = 0.0;
double val = 1.0;
int fact = 1;
for(int i = 1; i<= n; i++)
{
val = 1;
fact = 1;
for(int j = 1; j<=i; j++)
{
val *= x;
}
for(int k = 2*i - 1; k>1; k--)
{
fact *= k;
}
if(i%2 == 0)
{
sume += val/fact;
}
else
{
sumo += val/fact;
}
}
return (sumo - sume);
}