Radian to cos, sin and tan

I cant find out wrong at this part ,i cnt compile this program..

" switch (angle) "

//the coding is here

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

int main()
{
const double PI = 3.14259;

double angle;
double radian ;
double degree ;
double sin1;
double cos1;
double tan1;
double rad1;
cout << fixed << setprecision (4);
cout << " Please enter the angle in degree = " << "\n" << "or in radian = " ;
cin >> degree >> radian ;
rad1 = degree * PI / 180;

switch (angle)
{
case "angle" :if (degree >= 0 && degree <=360)
sin1 = sin(rad1);
cos1 = cos(rad1);
tan1 = tan(rad1);
break;

case"radian": if (radian >= 0 && radian <= 2*PI)
sin1 = sin(radian);
cos1 = cos(radian);
tan1 = tan(radian);
break;
}

return 0;
}


Switch only works with integers or characters. Not strings.
You can see an example of switch here: http://www.cplusplus.com/doc/tutorial/control/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
const double PI = 3.14259;

int angle;
double radian ;
double degree ;
double sin1;
double cos1;
double tan1;
double rad1;
cout << fixed << setprecision (4);
cout << " Select 1 for degrees\n"; 
cout << " or 2 for for radians\n" ;
cin >> angle;

switch (angle)
{
case 1 :	
	{
		cin >> degree;
		rad1 = degree * PI / 180;
		if (degree >= 0 && degree <=360)

		sin1 = sin(rad1);
		cos1 = cos(rad1);
		tan1 = tan(rad1);

		cout << "sin" << sin1 << endl;
		cout << "cos" << cos1 << endl;
		cout << "tan" << tan1 << endl;		
	}
break;

case 2: 
	{
		cin >> radian;
		if (radian >= 0 && radian <= 2*PI)
		sin1 = sin(radian);
		cos1 = cos(radian);
		tan1 = tan(radian);

		cout << "sin" << sin1 << endl;
		cout << "cos" << cos1 << endl;
		cout << "tan" << tan1 << endl;	
	}
break;
}

int x;
cin >> x;
return 0;
}
Last edited on
Note, your value for const double PI is incorrect, that will give wrong results even if the program works.
Thank you very much, i gt the point.. :)
Topic archived. No new replies allowed.