Sin Cos Tan table chart

hi guys i need help with this program.
i need to produce a table chart of sin cos and tan from angle 1-20 using do-while loop.
currently, i have this code but there's something wrong with the output. pls i need help thanks!

#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
clrscr();
int z=0;
double w,x,y;
w=sin(z);
x=cos(z);
y=tan(z);
cout<<"Angle"<<"\t"<<"Sin"<<"\t"<<"Cos"<<"\t"<<"Tan"<<endl;
do
{
cout<<z<<"\t"<<w<<"\t"<<x<<"\t"<<y<<"\t"<<endl;
z++;
}
while(z<=20);
getch();
return 0;
}


the output must be

Angle Sin Cos Tan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

and then the corresponding value in sin cos tan of the angles






try making z a float as the sin(), cos() tan() functions take their values as radians not degrees.

float z=0;

You will need to convert your angle (z) from degrees to radians when passing them to sin() etc..
i tried it but the output was still wrong

i change int to float z;
i added

w=sin(z*3.14159265/180);
x=cos(z*3.14159265/180);
y=tan(z*3.14159265/180);

but the output was still

Angle Sin Cos Tan
0 0 1 0
1 0 1 0
2 0 1 0
3 0 1 0
... 0 1 0
20 0 1 0

use

z*3.14159265/180.0

otherwise you'll divide by an int (180) and get an int result again.
Output your calculated angle in radians (next to where you output degrees) as well to check.
Last edited on
thanks! it worked now
Topic archived. No new replies allowed.