title: Getting an incorrect output for e^x function I made for class, and getting the wrong number of terms
body: <p>So for my Intro to computer programming class we have to write 3 separate functions, one to calculate factorials, one to calculate powers (x^n), and one to calculate the number of terms of the taylor series with the given error approximation. Everytime I run my program, it prints that Nterms=1, instead of like 100, 300, 1000, etc. </p>
  
  <p>It's probably a simple error in my loop, but I can't locate it. Any help is appreciated!</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  
  double power(float A, int B)
  {
      double sum=1.00;
      int nterms=1;
  
      while ( nterms &lt;= B &amp;&amp; B &gt; 0) 
      {
          sum = A*sum;
          nterms++;
      }
  
      return sum; 
  }
  
  double factorial(int b)
  {
      double fact=1.00;
  
      while (b &gt;= 2) 
      {
          fact = b*(b-1)*fact;
          b = b-2;
      }
  
      return fact;    
  }
  
  int Terms(float X, float a)
  {
      int N=1,l;
      double L,R;
  
  
  
      while (L &lt; a &amp;&amp; a &lt;= R)
      {
          l=N+1;
          L= (power(X,l)/(factorial(l)));
          R= (power(X,N)/(factorial(N)));
          N++;
      }
  
      return N;
  }
  
  int main()
  {
  
      float x, delta; 
      double sum=0.00, term=0.00;
      int n, Nterms;
  
  
      printf("Please enter a decimal number. x=");
      scanf("%f",&amp;x);
      printf("Please enter an another number. delta=");
      scanf("%f",&amp;delta);
  
  
      Nterms=Terms(x,delta);
      printf("Nterms=%d\n",Nterms);
  
      for(n=0;n&lt;Nterms;n++)
      {
           if( n==0 || n==1 )
          {
              sum = 1 + x;
          }
          else
          {
              sum = sum + term;
              term = (power(x,n))/(factorial(n));
          }   
      }
  
      printf("The approximation for e^(%f)=%.4f",x,sum);
  
      return 0;
  }
  </code></pre>