-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.cpp
More file actions
191 lines (162 loc) · 4.59 KB
/
Calculator.cpp
File metadata and controls
191 lines (162 loc) · 4.59 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
// Scientific Calculator here we go!
#include <iostream>
#include <cmath>
#define pi 3.14159265358979
using namespace std;
void welcomepage();
float sum(float x, float y);
float sub(float x, float y);
float mul(float x, float y);
float div(float x, float y);
double fac(float x);
int main()
{
int k;
float x, y, a, b, c, d, e, f;
welcomepage();
while (1)
{
cout << endl
<< "Enter the operation that you want to perform: " << endl;
cin >> k;
if (k == 0)
break;
switch (k)
{
case 1:
cout << "Enter the two numbers to add: " << endl;
cin >> x >> y;
a = sum(x, y);
cout << "SUM = " << a << endl;
break;
case 2:
cout << "Enter two numbers to subtract: " << endl;
cin >> x >> y;
b = sub(x, y);
cout << "SUBTRACTION = " << b << endl;
break;
case 3:
cout << "Enter two numbers to multiply: " << endl;
cin >> x >> y;
c = mul(x, y);
cout << "PRODUCT = " << c << endl;
break;
case 4:
cout << "Enter numerator: " << endl;
cin >> x;
cout << "Enter denominator: " << endl;
cin >> y;
d = div(x, y);
cout << "QUOTIENT = " << d << endl;
;
break;
case 5:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Enter the exponent: " << endl;
cin >> y;
cout << "Power = " << pow(x, y);
break;
case 6:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Square Root = " << sqrt(x);
break;
case 7:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Sine = " << sin(x * pi / 180);
break;
case 8:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Cosine = " << cos(x * pi / 180);
break;
case 9:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Tangent = " << tan(x * pi / 180);
break;
case 10:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Inverse of Sine = " << asin(x);
break;
case 11:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Inverse of Cosine = " << acos(x);
break;
case 12:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Inverse of Tangent = " << atan(x);
break;
case 13:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Logarithm = " << log(x);
break;
case 14:
cout << "Enter a number: " << endl;
cin >> x;
cout << "Logarithm with base 10 = " << log10(x);
break;
case 15:
cout << "Enter a number: " << endl;
cin >> x;
e = fac(x);
cout << "Factorial = " << e;
break;
default:
cout << "INVALID INPUT :(" << endl;
}
}
return 0;
}
float sum(float x, float y)
{
float sum;
sum = x + y;
return sum;
}
float sub(float x, float y)
{
float sub;
sub = x - y;
return sub;
}
float mul(float x, float y)
{
float mul;
mul = x * y;
return mul;
}
float div(float x, float y)
{
float div;
div = x / y;
return div;
}
double fac(float x)
{
double fact = 1;
for (x; x >= 1; x--)
fact = fact * x;
return fact;
}
void welcomepage()
{
cout << "(((((((((((((((((((::::::::::::::::: WELCOME TO YOUR CALCULATOR ::::::::::::::::::)))))))))))))))))))))" << endl;
cout << endl
<< "-------------------------------------------------------------------------------------------------------";
cout << endl
<< "\t\t\t\t HERE ARE THE OPERATIONS" << endl;
cout << "-------------------------------------------------------------------------------------------------------";
cout << endl
<< "1. ADDITION\t\t 2. SUBTRACTION\t\t 3. MULTIPLICATION\t\t 4. DIVISION" << endl;
cout << "5. EXPONENT\t\t 6. SQUARE ROOT\t\t 7. SINE\t\t\t 8. COSINE" << endl;
cout << "9. TANGENT\t\t 10.INVERSE OF SINE\t 11.INVERSE OF COSINE\t\t 12.INVERSE OF TANGENT" << endl;
cout << "13.LOGARITHM\t\t 14.LOG WITH BASE 10\t 15.FACTORIAL\t\t " << endl;
cout << "0. EXIT..." << endl;
}