-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculatorp.cpp
86 lines (67 loc) · 1.71 KB
/
calculatorp.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
#include<iostream>
using namespace std;
int main(){
string op_type;
cout << "Enter operation type (trig or no_trig or exp): ";
cin >> op_type;
if (op_type == "no_trig"){
double a;
cout << "Enter first number: ";
cin >> a;
double b;
cout << "Enter second number: ";
cin >> b;
string command;
cout << "Enter operation ";
cin >> command;
if (command == "/"){
cout << a/b;
}
else if (command == "*"){
cout << a*b;
}
else if (command == "+"){
cout << a+b;
}
else if (command == "-"){
if (a>b){
cout << a-b;
}
if (a<b){
cout << b-a;
}
}
}
else if (op_type == "trig"){
string func;
cout << "Enter function(sin/cos/tan): ";
cin >> func;
double x;
cout << "Enter value(in radians): ";
cin >> x;
if (func == "sin"){
cout << (x) - ((x*x*x)/(3*2*1)) + ((x*x*x*x*x)/(5*4*3*2*1)) - ((x*x*x*x*x*x*x)/(7*6*5*4*3*2*1));
}
if (func == "cos"){
cout << (1) - ((x*x)/(2*1)) + ((x*x*x*x)/(4*3*2*1)) - ((x*x*x*x*x*x)/(6*5*4*3*2*1));
}
if (func == "tan"){
cout << (x) + ((x*x*x)/(3)) + ((2*x*x*x*x*x)/(15));
}
}
else if (op_type == "exp"){
int power;
cout << "Enter power: ";
cin >> power;
int q;
cout << "Enter number: ";
cin >> q;
int answer;
answer = 1;
for (int i=1; i<= power; i++){
answer = answer*q;
}
cout << answer;
}
return 0;
}