title: My program to find the solution of a series is giving me wrong answers
body: <p>I was creating a program to find the solution to the series x - x^3/3! + x^5/5! - ... up to a certain term. The program is working but it is giving me wrong answers. Suppose if I take x = 5 and I wanted to find the sum up to 3 terms, it should give me 10.207(approx). But it is giving me an output of -15.8333. So please tell me where is the logical error in this program? I tried my best to find the error but I couldn't.</p>
  <p>Here is the program:</p>
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;cmath&gt;
      using namespace std;
      
      int N;
      unsigned long long int factorial(int x);
      long double evaluate(int x, int y = 1, int i = 1) {
          if (i &gt;= N) return 0;
          if (i % 2) return pow(x, y)/factorial(y) - evaluate(x, y + 2, i + 1);
          return pow(x, y)/factorial(y) + evaluate(x, y + 2, i + 1);
      }
      int main() {
          int x;
          cout &lt;&lt; &quot;Please enter a number: &quot;;
          cin &gt;&gt; x;
          cout &lt;&lt; &quot;Please enter the number of terms: &quot;;
          cin &gt;&gt; N;
          long double result = evaluate(x);
          cout &lt;&lt; &quot;The evaluation result of the series is &quot; &lt;&lt; result &lt;&lt; endl;
      }
      
      unsigned long long int factorial(int x) {
          if (x &lt; 0) return -1;
          if (x == 0) return 1;
          return x * factorial(x - 1);
  
      }
  </code></pre>