-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcalculator_final.cpp
More file actions
199 lines (178 loc) · 4.26 KB
/
calculator_final.cpp
File metadata and controls
199 lines (178 loc) · 4.26 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
#include <math.h>
#include <stdio.h>
// 1. Addition
void calcAddition() {
printf("\nEnter two numbers: \n");
int a, b;
scanf("%d%d", &a, &b);
int result = a + b;
printf("The sum is %d\n", result);
}
//Subtraction
void calcSubtraction() {
printf("\nEnter two numbers: \n");
int a, b;
scanf("%d%d", &a, &b);
int result = a - b;
printf("The subtraction of a and b is %d\n", result);
}
//Multiplication
void calcMultiplication() {
printf("\nEnter two numbers: \n");
int a, b;
scanf("%d%d", &a, &b);
int result = a * b;
printf("The product of a and b is %d\n", result);
}
//Division
void calcDivision() {
printf("\nEnter two numbers: \n");
int a, b;
scanf("%d%d", &a, &b);
int result = a / b;
printf("The division of a and b is %d\n", result);
}
//Exponent
void calcexpo() {
printf("\nEnter two numbers: \n");
int a, b;
scanf("%d%d", &a, &b);
int result = pow(a,b);
printf("The Exponentation of a and b is %d\n", result);
}
//Sine
void calcSine() {
printf("\nEnter the angle in degrees: ");
int angle;
scanf("%d", &angle);
// Convert degrees to radians
double radians = angle / 180.0 * 3.14;
double answer = sin(radians);
printf("The sine value is %f", answer);
}
//Cosine
void calcCosine() {
printf("\nEnter the angle in degrees: ");
int angle;
scanf("%d", &angle);
// Convert degrees to radians
double radians = angle / 180.0 * 3.14;
double answer = cos(radians);
printf("The cosine value is %f", answer);
}
//Tangent
void calcTan() {
printf("\nEnter the angle in degrees: ");
int angle;
scanf("%d", &angle);
// Convert degrees to radians
double radians = angle / 180.0 * 3.14;
double answer = tan(radians);
printf("The tangent value is %f", answer);
}
//Floor
void calcFloor() {
printf("\nEnter the angle in degrees: ");
int angle;
scanf("%d", &angle);
// Convert degrees to radians
double radians = angle / 180.0 * 3.14;
double answer = floor(radians);
printf("The floor value is %f", answer);
}
//Ceiling
void calcCeil() {
printf("\nEnter the angle in degrees: ");
int angle;
scanf("%d", &angle);
// Convert degrees to radians
double radians = angle / 180.0 * 3.14;
double answer = ceil(radians);
printf("The ceiling value is %f", answer);
}
//Round
void calcRound() {
printf("\nEnter the angle in degrees: ");
int angle;
scanf("%d", &angle);
// Convert degrees to radians
double radians = angle / 180.0 * 3.14;
double answer = round(radians);
printf("The rounding value is %f", answer);
}
//Absolute value
void calcAbs() {
printf("\nEnter the angle in degrees: ");
int angle;
scanf("%d", &angle);
// Convert degrees to radians
double radians = angle / 180.0 * 3.14;
double answer = abs(radians);
printf("The absolute value is %f", answer);
}
int main() {
int choice;
printf(
"Welcome to the Cool Calculator program!\n\n"
"1. Addition\n"
"2. Subtraction\n"
"3. Multiplication\n"
"4. Division\n"
"5. Exponentiation\n"
"6. Sine\n"
"7. Cosine\n"
"8. Tangent\n"
"9. Floor\n"
"10. Ceiling\n"
"11. Round\n"
"12. Absolute value\n\n"
"Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
// 1. Addition
case 1:
calcAddition();
break;
case 2:
// 2. Subtraction
calcSubtraction();
break;
case 3:
// 3. Multiplication
calcMultiplication();
break;
case 4:
// 4. Division
calcDivision();
break;
case 5:
// 5. Expo
calcexpo();
break;
// 6. Sine
case 6:
calcSine();
break;
case 7:
calcCosine();
break;
case 8:
calcTan();
break;
case 9:
calcFloor();
break;
case 10:
calcCeil();
break;
case 11:
calcRound();
break;
case 12:
calcAbs();
break;
default:
printf("Invalid choice!");
}
return 0;
}