help figuring out how to use sin/cos/tan before it shows the output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	const double PI = 3.14259;

	double angle;
	double radian;
	double degree;
	double sin1;
	double cos1;
	double tan1;
	double rad1;
	double result;
	double result1;
	double result2;
        const int r = 5
		cout << "Please enter the angel in degree: \n";
	rad1 = (degree*PI / 180);
	result = (rad1 * 180) / PI;
	result1 = (rad1 * 180) / PI;
	result2 = (rad1 * 180) / PI;

	cout << "Angle" << "\t" << "Sin" << "\t" << "Cos" << "\t" << "Tan" << endl;

	printf(" The sin of %f radians is %f. \n", result);
	printf(" The cos of %f radians is %f. \n", result1);
	printf(" The tan of %f radians is %f. \n", result2);

	return 0;
}


Okay so basically this is the code, although it probably has a lot of double I didn't know how to put it in a simpler form, I just have one question however,

1
2
3
4
rad1 = (degree*PI / 180);
	result = (rad1 * 180) / PI;
	result1 = (rad1 * 180) / PI;
	result2 = (rad1 * 180) / PI;


It should output the cosine and sine and tangent of the radian angle. How am i able to do that? I can't put a
1
2
3
result = ( sin rad1 * 180) / PI;
	result1 = (cos rad1 * 180) / PI;
	result2 = (tan rad1 * 180) / PI;


Thanks in advance! It's sort of urgent because the assignment is due in 3 hours so any help is appreciated!
Last edited on
Here's an example program using the <cmath> header, which contains trigonometric functions such as sin, cos and tan (or you can use the <math.h> header).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <cmath>

int main() {

	double degrees = 45.0;
	const double pi = 3.1415926;

	double result = ::sin(degrees * pi / 180.0);

	std::cout << "The Sine of " << degrees << " degree(s) is " << result << "." << std::endl;

	return 0;
}
Last edited on
Thanks for the quick reply!

Does this code seem to work properly?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
	const double PI = 3.14259;

	double angle;
	double radian;
	double degree;
	double rad1;
	double result;
	double result1;
	double result2;
	cout << "Please enter the angel in degree: \n";
	cin >> degree;
	cin.ignore();
	rad1 = (degree*PI / 180);

	result = ::sin(degree *PI / 180.0);
	result1 = ::cos(degree * PI / 180.0);
	result2 = ::tan(degree * PI / 180.0);

cout << "Angle" << "\t" << "Sin" << "\t" << "Cos" << "\t" << "Tan" << endl;

	cout << " The sine of " << degree << " degree is"<< result << " . " << endl;
	cout << " The cosine of " << degree << " degree is " << result1 << " . " << endl;
	cout << " The tangent of " << degree << " degree is " << result2 << " . " << endl;

	return 0;
}


I can't compile it because I use visual studio and It tells me that
the system cannot find the file specified.

Thanks!
The code seems to work fine. The results are correct.
I would remove the "stdafx.h" header. Also, I wouldn't include both <cmath> and <math.h>, just include one of them, but not both.

Additionally, your variables angle and radian (declared on lines 13 and 14) are unused. Your variable rad1 (declared on line 16) is set on line 23, but is also never used.
Thanks xismn! I appreciate all the help. I removed them but when I tried removing rad1 It showed me an error in the problem because there's this rad1 = (degree*PI / 180);. Unless there's another way of showing it, then I'd love it if you could tell me how.

You can simply remove rad1 = (degree*PI / 180);, since you're not using the variable rad1 for anything (besides the offending statement in question).
Last edited on
Topic archived. No new replies allowed.