title: Getting inf in a Taylor expansion for e^x, but only for small error bounds
body: <p>I am writing a program to approximate an exponential function, but I'm running into a problem. For small values of <code>err</code> the program messes up and just loops forever, getting approximations of inf every time. The program seems to be intolerant of larger and larger errors as larger <code>x</code>'s are entered. It works fine for, say, <code>x=1</code> and <code>err=10e-5</code>. As an example of when it doesn't work: <code>x=3</code> it works fine up to <code>err=10e-4</code> but when <code>err=10e-5</code> it results in inf.</p>
  
  <pre><code>//This program approximates e^x at a given x to a given accuracy
  #include&lt;algorithm&gt;
  #include&lt;cmath&gt;
  #include&lt;iostream&gt;
  #include&lt;string&gt;
  #include&lt;vector&gt;
  using namespace std;
  inline void keep_window_open() {char ch; cin &gt;&gt; ch;}
  class bad_entry{};
  int fac(int a) //function to find factorial
  {
      int f=1; //covers 0!
      for(int w=0; w&lt;a; ++w)
      {
          f*=(a-w);
      }
      return f;
  }
  int main()
  {
      try
      {
          double x=0;
          double ans=0;
          double err=0;
          int n=0; 
          cout &lt;&lt; "What number do you want to expand around?\n";
          cin &gt;&gt; x;
          if(!cin){throw bad_entry{};}
          cout &lt;&lt; "What would you like the error to be within?\n";
          cin &gt;&gt; err;
          if(!cin){throw bad_entry{};}
          double actual=exp(x);
          while(n&gt;=0)
          {
              ans += pow(x,n)/fac(n);
              cout &lt;&lt; "n=" &lt;&lt; n &lt;&lt; '\t' &lt;&lt; "Approx: " &lt;&lt; ans &lt;&lt; '\t' &lt;&lt; "Erro: " &lt;&lt; abs(actual-ans) &lt;&lt; '\n';
              if(abs(actual-ans)&lt;err)
              {
                  keep_window_open();
                  return 0;
              }
              ++n;
          }
      }
      catch(bad_entry)
      {
          cout &lt;&lt; "\nINVALID ENTRY\n";
          return 0;
      }
  }
  </code></pre>