/
trigonometry.c
249 lines (238 loc) · 6.16 KB
/
trigonometry.c
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
trigonometry (){
char selectora;
char selectorb;
puts ("do you have lines and angles, just angles or just lines? \nIf you have both angles and lines please enter \"al\"\nIf you only have lines please enter \"ll\"\nOr for the main menu please enter \"m\"");
scanf ("%c%c", &selectora, &selectorb);
flushall ();
selectora = toupper (selectora);
selectorb = toupper (selectorb);
if (selectora == 'L' && selectorb == 'L'){
lineline();
}else if (selectora == 'A' && selectorb == 'L'){
angleline();
}else if (selectora == 'L' && selectorb == 'A'){
angleline();
}else if (selectora == 'M' || selectorb == 'M'){
main();
}else {
trigonometry();
}
}
angleline (){
char selector;
puts ("what type of line do you have?\nis it (o)pposite or (a)djacent to the angle that you have or is it the (h)ypotenuse?\nor if you wish to go to the previous menu please enter \"p\"");
scanf ("%c", &selector);
flushall();
selector = toupper (selector);
if (selector == 'A'){
anglelineadjacent();
} else if (selector == 'O'){
anglelineopposite();
} else if (selector == 'H'){
anglelinehypotenuse();
} else if (selector == 'P'){
trigonometry();
} else {
angleline();
}
}
anglelineadjacent(){
double a,h,o,A,B,C,pi;
pi = 3.14159265358979323;
puts ("please enter the length of the adjacent line\n");
scanf ("%lf", &a);
flushall ();
puts ("please enter the size of the angle in degrees\n");
scanf ("%lf", &A);
flushall ();
A = A/(180/pi);
h = a/cos(A);
o = a*tan(A);
A = A*(180/pi);
B = 90;
C = 180-(A+B);
printf ("the hypotenuse is %lf long\n", h);
printf ("the adjacent is %lf long\n", a);
printf ("the opposite is %lf long\n", o);
printf ("the angle you gave me is %lf degrees\n", A);
printf ("angle B is %lf\n", B);
printf ("angle C is %lf\n", C);
sleep (1000);
printf ("\n\npress any key to exit or \"m\" to start from the beginning");
if (toupper(getchar())=='M'){
flushall();
main();
}else{
return (0);
}
}
anglelinehypotenuse(){
double a,h,o,A,B,C,pi;
pi = 3.14159265358979323;
puts ("please enter the length of the hypotenuse\n");
scanf ("%lf", &h);
flushall ();
puts ("please enter the size of the angle in degrees\n");
scanf ("%lf", &A);
flushall ();
A = A/(180/pi);
a = h*cos(A);
o = a*tan(A);
A = A*(180/pi);
B = 90;
C = 180-(A+B);
printf ("the hypotenuse is %lf long\n", h);
printf ("the adjacent is %lf long\n", a);
printf ("the opposite is %lf long\n", o);
printf ("the angle you gave me was %lf degrees\n", A);
printf ("angle B is %lf\n", B);
printf ("angle C is %lf\n", C);
sleep (1000);
printf ("\n\npress any key to exit or \"m\" to start from the beginning");
if (toupper(getchar())=='M'){
flushall();
main();
}else{
return (0);
}
}
anglelineopposite(){
double a,h,o,A,B,C,pi;
pi = 3.14159265358979323;
puts ("please enter the length of the opposite\n");
scanf ("%lf", &o);
flushall ();
puts ("please enter the size of the angle in degrees\n");
scanf ("%lf", &A);
flushall ();
A = A/(180/pi);
h = o/sin(A);
a = h*cos(A);
A = A*(180/pi);
B = 90;
C = 180-(A+B);
printf ("the hypotenuse is %lf long\n", h);
printf ("the adjacent is %lf long\n", a);
printf ("the opposite is %lf long\n", o);
printf ("the angle you gave me was %lf degrees\n", A);
printf ("angle B is %lf\n", B);
printf ("angle C is %lf\n", C);
sleep (1000);
printf ("\n\npress any key to exit or \"m\" to start from the beginning");
if (toupper(getchar())=='M'){
flushall();
main();
}else{
return (0);
}
}
lineline (){
char selectora, selectorb;
puts ("which lines do you have?\nplease enter \"ah\" for adjacent and hypotenuse, \"oh\" for opposite and hypotenuse or \"oa\" for opposite and adjacent\nOr if you want to go to the previous menu please enter \"P\"");
scanf ("%c%c", &selectora, &selectorb);
flushall();
selectora = toupper (selectora);
selectorb = toupper (selectorb);
if (selectora == 'O'){
if (selectorb == 'H'){
linelinesoh();
}else if (selectorb == 'A'){
linelinetoa();
}
}else if (selectora == 'H'){
if (selectorb == 'O'){
linelinesoh();
} else if (selectorb == 'A'){
linelinecah();
}
}else if (selectora == 'A'){
if (selectorb == 'O'){
linelinetoa();
}else if (selectorb == 'H'){
linelinecah();
}
}else if (selectora == 'P' || selectorb == 'P'){
trigonometry();
}else{
lineline();
}
}
linelinesoh(){
double a,o,h,A,B,C,pi;
pi = 3.14159265358979323;
puts ("please enter the opposite\n");
scanf ("%lf", &o);
flushall();
printf ("please enter the hypotenuse\n");
scanf ("%lf",&h);
flushall();
A = asin (o/h);
A = A*180/pi;
B = 90;
C = 180-(A+B);
printf ("A = %lf\n", A);
printf ("B = %lf\n", B);
printf ("C = %lf\n", C);
sleep (1000);
printf ("\n\npress any key to exit or \"m\" to start from the beginning");
if (toupper(getchar())=='M'){
flushall();
main();
}else{
return (0);
}
}
linelinecah(){
double a,o,h,A,B,C,pi;
pi = 3.14159265358979323;
puts ("Calculating \"A\" from the adjacent and hypotenuse\n");
puts ("please enter the adjacent\n");
scanf ("%lf",&a);
flushall();
printf ("please enter the hypotenuse\n");
scanf ("%lf",&h);
flushall();
A = a/h;
A = acos (A);
A = A *(180/pi);
B = 90;
C = 180-(A+B);
printf ("A = %lf\n", A);
printf ("B = %lf\n", B);
printf ("C = %lf\n", C);
sleep (1000);
printf ("\n\npress any key to exit or \"m\" to start from the beginning");
if (toupper(getchar())=='M'){
flushall();
main();
}else{
return (0);
}
}
linelinetoa(){
double a,o,h,A,B,C,pi;
pi = 3.14159265358979323;
puts ("Calculating \"A\" from the adjacent and opposite\n");
puts ("please enter the adjacent\n");
scanf ("%lf",&a);
flushall();
printf ("please enter the opposite\n");
scanf ("%lf",&o);
flushall();
A = o/a;
A = atan (A);
A = A * 180/pi;
B = 90;
C = 180-(A+B);
printf ("A = %lf\n", A);
printf ("B = %lf\n", B);
printf ("C = %lf\n", C);
sleep (1000);
printf ("\n\npress any key to exit or \"m\" to start from the beginning");
if (toupper(getchar())=='M'){
flushall();
main();
}else{
return (0);
}
}