title: Compute cos(x) to 0 when x is 90 degree or pi/2 radian in C++
body: <pre><code># include &lt;iostream&gt;
  # include &lt;math.h&gt;
  # include &lt;cstdlib&gt;
  using namespace std;
  
  double cosin_value( double value);
  double sin_value( double value);
  double big_degree (double value);
  double big_radian (double value);
  double x;
  double value;
  double degree;
  double radian;
  const double PI = 3.14159;
  
  char choice;
  char yes ;
  
  int main()
   {
  cout &lt;&lt; "Please enter an angle value =&gt; ";
  cin &gt;&gt; value;
  
  cout &lt;&lt; "Is the angle in Degree or Radian?" &lt;&lt; endl;
          cout &lt;&lt; "\t" &lt;&lt; "Type D if it is in Degree" &lt;&lt; endl;
          cout &lt;&lt; "\t" &lt;&lt; "Type R if it is in Radian" &lt;&lt; endl;
          cout &lt;&lt; "Your response =&gt; ";
          cin &gt;&gt; choice; //degree or radian?
  
          cout.setf(ios::fixed);
          cout.setf(ios::showpoint);
          cout.precision(10);
  
      if (choice == 'D' || choice == 'd')
      {
          big_degree (value);
          cout &lt;&lt; " " &lt;&lt; "sin(x)   = " &lt;&lt; "\t" &lt;&lt; sin_value(degree) &lt;&lt; endl;
          cout &lt;&lt; " " &lt;&lt; "cos(x)   = " &lt;&lt; "\t" &lt;&lt; cosin_value(degree) &lt;&lt; endl;
          cout &lt;&lt; " " &lt;&lt; "tan(x)   = " &lt;&lt; "\t" &lt;&lt;  sin_value(degree)/cosin_value(degree) &lt;&lt; endl;
      }
      else if (choice == 'R' || choice == 'r')
      {   
          cout &lt;&lt; " " &lt;&lt; "sin(x)   = " &lt;&lt; "\t" &lt;&lt; sin_value(radian) &lt;&lt; endl;
          cout &lt;&lt; " " &lt;&lt; "cos(x)   = " &lt;&lt; "\t" &lt;&lt; cosin_value(radian) &lt;&lt;  endl;
          cout &lt;&lt; " " &lt;&lt; "tan(x)   = " &lt;&lt; "\t" &lt;&lt;   sin_value(radian)/cosin_value(radian) &lt;&lt; endl;
      }   
      return 0;
  }
  
  // Sine,cosine functions
  // angle -360&lt;value&lt;360
  
  double sin_value( double value)
  {
  int count=1;
  
  double sine, num, dem, sign, term;
  sine=0;
  sign = 1;   
  num = value;
  dem = count;
  
  while ( count &lt;= 20 )
  {
      term = (num/dem);
      sine = sine + term*sign;
      num = num*value*value;
      count = count + 2;
      dem = dem * count * (count-1);
      sign = -sign;
  
  }
  return (sine);  
  }   
  
  double cosin_value( double value)
  {
  int count=0;
  double cosine, num, dem, sign, term;
  cosine=0;
  sign = 1;
  
  num = 1;
  dem = 1;
  
  while ( count &lt;= 20 )
  {
      term = (num/dem);
      cosine = cosine + term*sign;
      num = num*value*value;
      count = count + 2;
      dem = dem * count * (count-1);
      sign = -sign;
  }
  return (cosine);
  }   
  
  double big_degree (double value)
  {
  int result;
  const int angle=360;
  if (value &gt;= 360 || value &lt;= -360)
  {
      result=value/angle;
      degree=(value-(result* angle))*PI/180;
  }    
  else
  {
      degree = (value*PI)/180;
  }   
  return (degree);
   }  
  
  double big_radian (double value)
  {
  int result;
  
  if (value &gt;= 2*PI || value &lt;= -2*PI)
  {
      result=value/(2*PI);
      radian=(value-(result* 2*PI));
  }    
  else
  {
      radian = value;
  }   
  return (radian);
  }   
  </code></pre>
  
  <p>Hi, this is basically the whole program I wrote for calculating trigonometric value using the extent knowledge I knew in C++ as a beginner. For a better view, you can refer to this link regarding my code above :<a href="http://codepad.org/dChy8x2E" rel="nofollow">codepad.org</a>
  the line starting from line 114 onwards are the function that I created. There's a problem there where how can I compute my <strong>cosx</strong> to be 0 when the value is 90 degree or pi/2 radian?
  since the program will still calculate <strong>tanx</strong> for me even the value is 90 degree.
  Let's say by giving value <strong>90 degree</strong> to the program, it will give me the value of <strong>0.0000013268</strong> instead of <strong>0.000000</strong>
  sorry, since I'm just a beginner, the code will look weird for you guys.
  I appreciate your guides!
  <strong>double big_degree(double value)</strong> means when the <strong>value is >= 360 or &lt;= -360*</strong></p>