calculating sin, cos, and tan functions

I have a program that calculates sin, cos, and tan but it displays it in radian mode. If i want to get this to degrees i have to do sin(x) * PI/180. When i do this it does not give me the right answer, please help. Here is code:

#include <iostream>
using namespace std;
#include <iomanip>
#include <cmath>

const PI = 3.14159265359;


int main()
{
// constant variable can be used to specify array size
const int arraySize = 45;
int s[ arraySize ]; // array s has 45 elements

cout << fixed << setprecision(6);

for ( int i = 1; i <= arraySize; i++ ) // set the values
sIdea = i++;

cout <<"Angle\n" << "(Degrees)" << setw( 9 ) <<"Sine"<< setw(15)
<<"Cosine"<< setw(14) <<"Tangent"<<endl;

// output contents of array s in tabular format
for ( int j = 1; j <= arraySize; j++ )
cout << setw( 2 ) << j << setw( 20 ) << sin(j) << setw(13)
<< cos(j) << setw(13) << tan(j) << endl;

return 0;
} // end main



Answer this question

calculating sin, cos, and tan functions

  • Mitchell Baldwin

    I think you are making a wrong calculation. When you say "If i want to get this to degrees i have to do sin(x) * PI/180. " this is wrong!!

    x is actually the angle so you can not multiply the result of sin by the PI/180 ratio, also the ratio must be swapped (180/PI). It has sense only If you were applying asin (the inverse of sin aka arcsin), so the result is an angle in radians and after that you can multiply to obtain degrees (see it below).

    angle in degrees = asin(a0)*(180/PI).

    The result of sin(x) is just a value that represents the vertical projection of a vector that rotates around the origin of a particular coordinate system, so it doesn't return angles it returns the projection.

    =)



  • calculating sin, cos, and tan functions