-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrigonometryProgram.cpp
More file actions
312 lines (246 loc) · 10.1 KB
/
Copy pathTrigonometryProgram.cpp
File metadata and controls
312 lines (246 loc) · 10.1 KB
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#include <iostream>
#include <cmath>
#define PI 3.141592654
int main() {
double a; // The A side of a triangle -- Will be used for the adjacent value
double b; // The B side of a triangle -- Will be used for the opposite value
double c; // The C side of a triangle -- Will be used for the hypotenuse value
double degree; // The degree of a specific point in a triangle
char choice1; // Choose which theorem to calculate
char choice2; // Choose a side of a triangle
char choice3; // Choose whether to calculate the angle or a side of a triangle (sine, cosine, and tangent exclusive)
std::cout << "**************************************** TRIGONOMETRY PROGRAM ****************************************\n";
std::cout << "\nPlease choose which theorem you'd like to calculate (Pythagoras theorem, sine, cosine, tangent): ";
std::cin >> choice1;
choice1 = tolower(choice1); // Converts whatever the user entered into a lowercase (makes it easier for me lol)
switch (choice1) {
case 'p': // Pythagoras theorem
std::cout << "\nWhich side are you looking to find? (A, B, C): ";
std::cin >> choice2;
choice2 = tolower(choice2);
while (choice2 != 'a' && choice2 != 'b' && choice2 != 'c') { // If the user inputted an incorrect value
std::cout << "\nValue invalid. Please try again.";
std::cout << "\nWhich side are you looking to find? (A, B, C): ";
std::cin >> choice2;
choice2 = tolower(choice2);
}
switch (choice2) {
case 'a': // Calculate the value of side A
std::cout << "\nWhat's the value of B?: ";
std::cin >> b;
while (b <= 0) {
std::cout << "Value invalid. Please try again.\n";
std::cout << "\nWhat's the value of B?: ";
std::cin >> b;
}
std::cout << "\nWhat's the value of C?: ";
std::cin >> c;
while (c <= 0 || c <= b) {
std::cout << "Value invalid. Please try again.\n";
std::cout << "\nWhat's the value of C?: ";
std::cin >> c;
}
a = sqrt(c * c - b * b); // Formula for calculating the value of side A
std::cout << "Side A is equal to " << a << "cm.\n";
break;
case 'b':
std::cout << "\nWhat's the value of A?: ";
std::cin >> a;
while (a <= 0) {
std::cout << "Value invalid. Please try again.\n";
std::cout << "\nWhat's the value of A?: ";
std::cin >> a;
}
std::cout << "\nWhat's the value of C?: ";
std::cin >> c;
while (c <= 0 || c <= a) {
std::cout << "Value invalid. Please try again.\n";
std::cout << "\nWhat's the value of C?: ";
std::cin >> c;
}
b = sqrt(c * c - a * a);
std::cout << "Side B is equal to " << b << "cm.\n";
break;
case 'c':
std::cout << "\nWhat's the value of A?: ";
std::cin >> a;
while (a <= 0) {
std::cout << "Value invalid. Please try again.\n";
std::cout << "\nWhat's the value of A?: ";
std::cin >> a;
}
std::cout << "\nWhat's the value of B?: ";
std::cin >> b;
while (b <= 0) {
std::cout << "Value invalid. Please try again.\n";
std::cout << "\nWhat's the value of B?: ";
std::cin >> b;
}
c = sqrt(a * a + b * b);
std::cout << "Side C is equal to " << c << ".\n";
break;
}
break;
case 's':
std::cout << "\nAre you calculating the unknown value or the angle? (V or A): ";
std::cin >> choice3;
choice3 = tolower(choice3);
while (choice3 != 'v' && choice3 != 'a') {
std::cout << "\nValue invalid. Please try again.";
std::cout << "\nAre you calculating the unknown value or the angle? (V or A): ";
std::cin >> choice3;
choice3 = tolower(choice3);
}
switch (choice3) {
case 'v':
std::cout << "\nWhich value is known, A (opposite) or C (hypotenuse)?: ";
std::cin >> choice2;
choice2 = tolower(choice2);
while (choice2 != 'a' && choice2 != 'c') {
std::cout << "\nValue invalid. Please try again.";
std::cout << "\nWhich value is known, A (opposite) or C (hypotenuse)?: ";
std::cin >> choice2;
choice2 = tolower(choice2);
}
switch (choice2) {
case 'a':
std::cout << "\nWhat is the value of A?: ";
std::cin >> a;
while (a <= 0) {
std::cout << "\nValue invalid. Please try again.";
std::cout << "\nWhat is the value of A?: ";
std::cin >> a;
}
std::cout << "\nWhat's the value of the angle? Must be less than 90 degrees: ";
std::cin >> degree;
while (degree <= 0 || degree >= 90) {
std::cout << "\nValue invalid. Please try again.";
std::cout << "\nWhat's the value of the angle? Must be less than 90 degrees: ";
std::cin >> degree;
}
c = a / sin(degree);
std::cout << "\nThe value of C is " << c << ".";
break;
case 'c':
std::cout << "\nWhat's the value of C?: ";
std::cin >> c;
std::cout << "\nWhat's the value of the angle? Must be less than 90 degrees: ";
std::cin >> degree;
a = c * sin(degree);
std::cout << "\nThe value of A is " << a << ".";
break;
default:
std::cout << "\nWait, how did you get here?"; // This shouldn't happen...
break;
}
break;
case 'a':
std::cout << "\nWhat's the value of A (opposite)?: ";
std::cin >> a;
std::cout << "\nWhat's the value of C (hypotenuse)?: ";
std::cin >> c;
while (c <= a) {
std::cout << "\nValue invalid. Please try again.";
std::cout << "\nWhat's the value of C (hypotenuse)?: ";
std::cin >> c;
}
degree = asin(a / c) * 180 / PI;
std::cout << "\nThe degree in this right angle triangle is " << degree << " degrees.";
break;
default:
std::cout << "\nWanna know something? This was made by an 18 year old bisexual furry."; // This also shouldn't happen...
break;
}
break;
case 'c':
std::cout << "\nAre you calculating the unknown value or the angle? (V or A): ";
std::cin >> choice3;
choice3 = tolower(choice3);
switch (choice3) {
case 'v':
std::cout << "\nWhich value is known, B (adjacent) or C (hypotenuse)?: ";
std::cin >> choice2;
choice2 = tolower(choice2);
switch (choice2) {
case 'b':
std::cout << "\nWhat's the value of B?: ";
std::cin >> b;
std::cout << "\nWhat's the value of the angle? Must be less than 90 degrees: ";
std::cin >> degree;
c = b / cos(degree);
std::cout << "\nThe value of C is " << c << ".";
break;
case 'c':
std::cout << "\nWhat's the value of C?: ";
std::cin >> c;
std::cout << "\nWhat's the value of the angle? Must be less than 90 degrees: ";
std::cin >> degree;
b = c * cos(degree);
std::cout << "\nThe value of B is " << b << ".";
break;
}
break;
case 'a':
std::cout << "\nWhat's the value of B (adjacent)?: ";
std::cin >> b;
std::cout << "\nWhat's the value of C (hypotenuse)?: ";
std::cin >> c;
degree = acos(b / c) * 180 / PI;
std::cout << "\nThe degree in this right triangle is " << degree << " degrees.";
break;
default:
std::cout << "\nUwU";
break;
}
break;
case 't':
std::cout << "\nAre you calculating the unknown value or the angle? (V or A): ";
std::cin >> choice3;
choice3 = tolower(choice3);
switch (choice3) {
case 'v':
std::cout << "\nWhich value is known, A (opposite) or B (adjacent)?: ";
std::cin >> choice2;
choice2 = tolower(choice2);
switch (choice2) {
case 'a':
std::cout << "\nEnter the value of A: ";
std::cin >> a;
std::cout << "\nWhat's the value of the angle? Must be less than 90 degrees: ";
std::cin >> degree;
b = a / tan(degree);
std::cout << "\nThe value of B is " << b << ".";
break;
case 'b':
std::cout << "\nEnter the value of B: ";
std::cin >> b;
std::cout << "\nWhat's the value of the angle? Must be less than 90 degrees: ";
std::cin >> degree;
a = b * tan(degree);
std::cout << "\nThe value of A is " << a << ".";
break;
default:
std::cout << "\nIntruder alert! A red spy is in the base! A red spy is in the base? Hut hut hut hut. Protect the briefcase! We need to protect the briefcase! Yo, a little help here! Alright, alright I got it. Stand back son. 1, 1, 1, um... 1. Let's go, let's go, let's go. Incoming! Hey it's still here. Alright then. Ahem, gentlemen. I see the briefcase is safe. Safe and sound. Yeah, it is. Tell me, did anyone happen to kill a red spy on the way here? No? Then we still have a problem. And a knife. Ooh, big problem. I've killed plenty of spies. The dime-a-dozen backstabbing scumbags, like you. Ow! No offense. If you manage to kill them, I assure you they were not like me. And nothing, nothing like the man loose inside this building. What, are you president of his fan club? No. That would be your mother. What the? Wait...? Indeed, and now he's here to f**k us! So listen up boy, or pornography starring your mother will be the second worst thing to happen to you today. Oh! Give me that! This spy has already breached our defenses. Sentry down! You've seen what he's done to our colleagues! And worst of all, it could be any one of us. It could be in this very room. It could be you. It could be me. It could even be-- Woah, woah, woah! Woah. What? It was obvious. He's the red spy. Watch, he'll turn red any second now. Any second now. See! Red! No wait, that's blood. So, we still got problem. Big problem. Alright, who's ready to go find this spy? Right behind you. Oh? Ah, ma petite chou fleur.";
break;
}
break;
case 'a':
std::cout << "\nWhat's the value of A (opposite)?: ";
std::cin >> a;
std::cout << "\nWhat's the value of B (adjacent)?: ";
std::cin >> b;
degree = atan(a / b) * 180 / PI;
std::cout << "\nThe degree in this right triangle is " << degree << " degrees.";
break;
default:
std::cout << "\nHey all, Scott here, and this is bad! Real bad!";
break;
}
break;
default:
std::cout << "ERROR: " << choice1 << " is not valid! Exiting...\n";
break;
}
std::cout << "\n******************************************* END OF PROGRAM *******************************************\n";
system("pause");
}