Help on first big project, having trouble with Trigonometric Functions

Hey guys need some help. First big project of the semester. I need some help on it as this class is very difficult for me to understand. I wrote a code with a menu and different functions my Professor wanted. It works however im having trouble with the trigonometric functions. I got the basics ones Sine, Cosine,and Tangent to work with mostly all numbers except 180 and 360 with sine, 90 and 270 with cosine, and 180 and 360 with tangent. Basically whenever I am supposed to get zero back I do not. As far as the inverse functions, arc tangent 2 and hyperbolic functions, I need major help. Ive never used arc tangent 2 or hyperbolic so im pretty lost. I figured out afterwards that I could have used input, input1 and input2 for the whole code to not have as many variables but I had already written everything and it works. So please some help with the trigonometric stuff. Really appreciated. Need as much help as I can get in this class.

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
  #include <iostream>
#include <cmath>

using namespace std;

int main ()
{
	int index;
	double input1, input2, input3, input4, input5, input6, input7, input8, input9, input10, output, output2, output3, output4, output5, output6, output7, output8, output9, output10;
	double a, b, c, d, e, f, g, h, i, j, k, l, m, n, o;
	double a1, b1, c1, d1, e1, f1, g1, h1, i1, j1 , k1, l1, m1, n1, o1, p1, q1, r1, s1, t1, u1, v1, w1, x1, y1, z1;
	double pi= acos(-1.0);
	bool quit, back, back1; 
	




			case 3:
			do
			{
				cout << "0. Back\n";
				cout << "1. Compute absolute value\n";
				cout << "2. Compute square root\n";
				cout << "3. Raise to a power\n";
				cout << "4. Compute exponential funcation\n";
				cout << "5. Compute natural logarithm\n";
				cout << "6. Compute common logarithm\n";
				cout << "7. Compute sine\n";
				cout << "8. Compute cosine\n";
				cout << "9. Compute tangent\n";
				cout << "10. Compute arc sine\n";
				cout << "11. Compute arc cosine\n";
				cout << "12. Compute arc tangent\n";
				cout << "13. Compute arc tangent with two parameters\n";
				cout << "14. Compute hyperbolic sine\n";
				cout << "15. Compute hyperbolic cosine\n";
				cout << "16. Compute hyperbolic tangent\n";
				cout << "17. Round up value\n";
				cout << "18. Round down value\n";
				back = false;
				cin >> index;
				switch(index)
				{
				case 0:
					back = true;
					break;
										
				case 7:
					do
					{
						cout << "0. Back\n";
						cout << "1. Sine (Sin)\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0: 
							back1= true;
							break;
						case 1 :
							cout << "Enter a number (in degrees) you would like to compute the sine of:\n";
							cin >> h1;  
							cout << " The sine of " << h1 << " in degrees is " << sin(h1*pi/180)<< "\n";
							break;
						}
					}while(back1 != true);
					break;
				case 8:
					do
					{
						cout << "0. Back\n";
						cout << "1. Cosine (Cos)\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0:
							back1 = true;
							break;
						case 1:
							cout << "Enter a number (in degrees) you would like to compute the cosine of:\n";
							cin >> i1 ;
							cout << " The cosine of " << i1 << " in degrees is " << cos(i1 * pi / 180)<< "\n";
							break;
						}
					}while(back1 != true);
					break;
				case 9:
					do
					{
						cout << "0. Back\n";
						cout << "1. Tangent (Tan)\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0:
							back1 = true;
							break;
						case 1:
							cout << "Enter a number (in degrees) you would like to compute the tangent of:\n";
							cin >> j1 ;
							cout << " The tangent of " << j1 << " in degrees is " << tan(j1*pi/180)<< "\n";
							break;
						}
					}while(back1 != true);
					break;
				case 10:
					do
					{
						cout << "0. Back\n";
						cout << "1.Arc Sine (asin)\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0:
							back1 = true;
							break;
						case 1 :
							cout << "Enter a number (in degrees) you would like to compute the arc sine of:\n";
							cin >> k1 ;
							cout << " The arc sine of " << k1 << " in degrees is " << asin(k1) *180.0 / pi << "\n";
							break;
						}
					}while(back1 != true);
					break;
				case 11:
					do
					{
						cout << "0. Back\n";
						cout << "1.Arc Cosine (acos)\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0 :
							back1 = true;
							break;
						case 1 :
							cout << "Enter a number (in degrees) you would like to compute the arc cosine of:\n";
							cin >> l1 ;
							cout << " The arc cosine of " << l1 << " in degrees is " << acos(l1)* 180 / pi << "\n";
							break;
						}
					}while(back1 != true);
					break;
				case 12:
					do
					{
						cout << "0. Back\n";
						cout << "1.Arc Tangent (atan)\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0 : 
							back1 = true;
							break;
						case 1 :
							cout << "Enter a number (in degrees) you would like to compute the arc tangent of:\n";
							cin >> m1 ;
							cout << " The arc tangent of " << m1 << " in degrees is " << atan(m1) * 180/ pi << "\n";
							break;
						}
					}while(back1 != true);
					break;
				case 13:
					do
					{
						cout << "0. Back\n";
						cout << "1. atan2\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0 : 
							back1 = true;
							break;
						case 1:
							cout << "Enter the y value of the Arc Tangent 2:\n";
							cin >> n1;
							cout << "Enter the x value of the Arc Tangent 2:\n";
							cin >> z1;
							cout << " The Arc Tangent 2 (y,x) is " << atan2(n1,z1) << "\n";
						}
					}while(back1 != true);
					break; 
				case 14:
					do
					{
						cout << "0. Back\n";
						cout << "1. Hyperbolic Sine (sinh)\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0:
							back1 = true;
							break;
						case 1:
							cout << "Enter a number (in degrees) you would like to compute the hyperbolic sine of\n";
							cin >> o1 ;
							cout << " The hyperbolic sine of " << o1 << " in degrees is " << sinh(o1) << "\n";
							break;
						}
					}while(back1 != true);
					break;
				case 15:
					do 
					{
						cout << "0. Back\n";
						cout << "1. Hyperbolic Cosine (cosh)\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0:
							back1 = true;
							break;
						case 1:
							cout << "Enter a number (in degrees) you would like to compute the hyperbolic cosine of\n";
							cin >> p1 ;
							cout << " The hyperbolic cosine of " << p1 << " in degrees is " << cosh(p1) << "\n";
							break;
						}
					}while(back1 != true);
					break;
				case 16:
					do
					{
						cout << "0. Back\n";
						cout << "1. Hyperbolic Tangent (tanh)\n";
						back1 = false;
						cin >> index;
						switch(index)
						{
						case 0:
							back1 = true;
							break;
						case 1:
							cout << "Enter a number (in degrees) you would like to compute the hyperbolic tangent of\n";
							cin >> q1 ;
							cout << " The hyperbolic oosine of " << q1 << " in degrees is " << tanh(q1) << "\n";
							break;
						}
					}while(back1 != true);
					break;
						
		}



	}while(quit != true);

	system ("pause");
	return 0;
}


Codes pretty long guys. It doesn't all fit here. I put the section I need help with.
Thank You in Advanced
Last edited on
Watch out for floor divisions as it will decrease the accuracy of your results.

Aceix.
wrote a code with a menu and different functions my Professor wanted.

I don't see any "functions" in the code you provided. But it looks like you really could use some functions to reduce the size of main(), a function for each menu item would probably make things easier to implement and troubleshoot.


I can say that when you are doing the sine of 180 degrees, the computer is saying it is more than 0 by the thinnest hair (1.22465 * 10 ^ -16 is pretty darn close to zero). There are two solutions I know of to make it read 0 : either have a special case set up to check if the number entered is a multiple of 180 and output 0 without the actual calculation (which SHOULD be OK since these solutions are known), or to do the advice found here:

http://stackoverflow.com/questions/6368055/problems-with-cmath-and-the-sin-function

Which is the only real advice I could find online regarding the issue. I will quote it here for easy reference:
For best accuracy, start with modulo reduction, then resolve the value to an octant, then convert an angle from 0 to 45 degrees into 0 to pi/2 radians. Otherwise some math libraries may report that the sine of 180 degrees isn't exactly zero [and possibly go so far as to waste time trying to compute exactly how far it is from zero]. – supercat Jun 4 '14 at 17:28
Last edited on
...So if you have finished your assignment or not, I usually use mathisfun.com for algebraic/trigonometric stuff I am not too familiar with, but this looks like cmath library stuff. So I would really either google what the things are you are trying to figure out (I think atan2 may be what you are referencing by arc tangent 2), and refer to cmath reference section on this site for the function descriptions: http://www.cplusplus.com/reference/cmath/

You just click on the name of the function and it gives you all the data about it.
Topic archived. No new replies allowed.