program giving a compile time error

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.

This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* 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);

using namespace 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);
}
Last edited on
Well, it works fine on both cpp.sh and Code::Blocks IDE, it even gives the right answer. The problem is definitely not in the code.
what compiler do you use?
Topic archived. No new replies allowed.