title: How do I end this while loop with a precision of 0.00001 ([C++],[Taylor Series])?
body: <p>I'm working on this program that approximates a taylor series function. I have to approximate it so that the taylor series function stops approximating the sin function with a precision of .00001. In other words,the absolute value of the last approximation minus the current approximation equals less than or equal to 0.00001. It also approximates each angle from 0 to 360 degrees in 15 degree increments. My logic seems to be correct, but I cannot figure out why i am getting garbage values. Any help is appreciated!</p>
  
  <pre><code>#include &lt;math.h&gt;
  #include &lt;iomanip&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;cmath&gt;
  double fact(int x){
     int F = 1;
      for(int i = 1; i &lt;= x; i++){
          F*=i;
      }
      return F;
     }
  double degreesToRadians(double angle_in_degrees){
    double rad = (angle_in_degrees*M_PI)/180;
    return rad;
   }
   using namespace std;
  double mySine(double x){
     int current =99999;
     double comSin=x;
     double prev=0;
     int counter1 = 3;
     int counter2 = 1;
     while(current&gt;0.00001){
      prev = comSin;
      if((counter2 % 2) == 0){
        comSin += (pow(x,(counter1))/(fact(counter1)));
      }else{
        comSin -= (pow(x,(counter1))/(fact(counter1)));
      }
     current=abs(prev-comSin);
     cout&lt;&lt;current&lt;&lt;endl;
     counter1+=2;
     counter2+=1;
     }
     return comSin;
  }
  
  using namespace std;
  int main(){
  cout&lt;&lt;"Angle\tSine"&lt;&lt;endl;
   for (int i = 0; i&lt;=360; i+=15){
   cout&lt;&lt;i&lt;&lt;"\t"&lt;&lt;mySine(degreesToRadians(i));
   }
  
  
  
  
   }
  </code></pre>