-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.cpp
111 lines (97 loc) · 3.1 KB
/
calc.cpp
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
#include <iostream>
float add(float a, float b) {
return a + b;
}
float sub(float a, float b) {
return a - b;
}
float multi(float a, float b) {
return a * b;
}
float divi(float a, float b) {
return a / b;
}
float perc(float a, float b) {
return (a / b) * 100;
}
float sroot(float a) {
return a * a;
}
float area(float a, float b) {
return a * b;
}
float circum(float a) {
return 2 * 3.14159 * a;
}
float radaii(float a) {
return 3.14159 * a * a;
}
int main() {
int choice;
float x, y;
char cont;
do {
std::cout << "What action you want to take?:\n\t1. Add\n\t2. Subtract\n\t3. Multiply\n\t4. Division\n\t5. Percentage\n\tEnter the number: ";
std::cin >> choice;
switch(choice) {
case 1:
std::cout << "Enter first number: ";
std::cin >> x;
std::cout << "Enter second number: ";
std::cin >> y;
std::cout << "The sum is: " << add(x, y) << std::endl;
break;
case 2:
std::cout << "Enter first number: ";
std::cin >> x;
std::cout << "Enter second number: ";
std::cin >> y;
std::cout << "The difference is: " << sub(x, y) << std::endl;
break;
case 3:
std::cout << "Enter first number: ";
std::cin >> x;
std::cout << "Enter second number: ";
std::cin >> y;
std::cout << "The product is: " << multi(x, y) << std::endl;
break;
case 4:
std::cout << "Enter first number: ";
std::cin >> x;
std::cout << "Enter second number: ";
std::cin >> y;
std::cout << "The quotient is: " << divi(x, y) << std::endl;
break;
case 5:
std::cout << "Enter the part: ";
std::cin >> x;
std::cout << "Enter the whole: ";
std::cin >> y;
std::cout << "The percentage is: " << perc(x, y) << std::endl;
break;
case 6:
std::cout << "Enter the number: ";
std::cin >> x;
std::cout << "The square root is: " << sroot(x) << std::endl;
break;
case 7:
std::cout << "Enter the length: ";
std::cin >> x;
std::cout << "Enter the width: ";
std::cin >> y;
std::cout << "The area is: " << area(x, y) << std::endl;
break;
default:
std::cout << "Invalid choice" << std::endl;
break;
}
std::cout << "Do you want to perform another operation? (y/n): ";
std::cin >> cont;
if(cont != 'y' && cont != 'Y' && cont != 'n' && cont != 'N') {
std::cout << "Invalid choice" << std::endl;
std::cout << "Program ends" << std::endl;
break;
}
} while (cont == 'y' || cont == 'Y');
return 0;
}