forked from BaseMax/TinyCalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
161 lines (149 loc) · 2.89 KB
/
main.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
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
/**
*
* @Name : TinyCalculator/main.cpp
* @Version : 1.0
* @Programmer : Max
* @Date : 2019-05-17
* @Released under : https://github.com/BaseMax/TinyCalculator/blob/master/LICENSE
* @Repository : https://github.com/BaseMax/TinyCalculator
*
**/
#include "main.hpp"
void parseAddition() {
float a=0, b=0;
cout << "Enter the first value: ";
cin >> a;
cout << "Enter the second value: ";
cin >> b;
cout << a + b << endl;
}
void parseSubtraction() {
float a=0, b=0;
cout << "Enter the first value: ";
cin >> a;
cout << "Enter the second value: ";
cin >> b;
cout << a - b << endl;
}
void parseMultiplication() {
float a=0, b=0;
cout << "Enter the first value: ";
cin >> a;
cout << "Enter the second value: ";
cin >> b;
cout << a * b << endl;
}
void parseDivision() {
float a=0, b=0;
cout << "Enter the first value: ";
cin >> a;
cout << "Enter the second value: ";
cin >> b;
if(b != 0) {
cout << a / b << endl;
}
}
void parseExponentiation() {
float a=0, r=0;
int b=0;
cout << "Enter the first value: ";
cin >> a;
cout << "Enter the second value: ";
cin >> b;
r=pow(a, b);
cout << r << endl;
}
void parseSquareRoot() {
float a=0, r=0;
cout << "Enter the value: ";
cin >> a;
r=sqrt(a);
cout << r << endl;
}
void parseSine() {
float a=0, r=0;
cout << "Enter the value: ";
cin >> a;
r=sin(a);
cout << r << endl;
}
void parseCosine() {
float a=0, r=0;
cout << "Enter the value: ";
cin >> a;
r=cos(a);
cout << r << endl;
}
void parseTangent() {
float a=0, r=0;
cout << "Enter the value: ";
cin >> a;
r=tan(a);
cout << r << endl;
}
void help() {
cout << "\n\n";
cout << " Tiny Calculator ------------------------------\n";
cout << "\t a\t\t Addition of two number\n";
cout << "\t m\t\t Subtraction of two number\n";
cout << "\t u\t\t Multiplication of two number\n";
cout << "\t d\t\t Division of two number\n";
cout << "\t p\t\t Exponentiation of two number\n";
cout << "\t r\t\t SquareRoot of a number\n";
cout << "\t s\t\t Sine of anumber\n";
cout << "\t c\t\t Cosine of anumber\n";
cout << "\t t\t\t Tangent of a number\n";
cout << "\t h\t\t Help\n";
cout << "\t e\t\t Exit\n";
cout << "\n\n";
}
void error() {
cout << "Error : Input is anonymous!\n";
}
int main(int argc, char** argv) {
unsigned char type;
bool flag=true;
while(flag) {
cout << "------------------\n(h) For help\n(e) To exit\nEnter Your type: ";
cin >> type;
switch(type) {
case 'a':
parseAddition();
break;
case 'm':
parseSubtraction();
break;
case 'u':
parseMultiplication();
break;
case 'd':
parseDivision();
break;
case 'p':
parseExponentiation();
break;
case 'r':
parseSquareRoot();
break;
case 's':
parseSine();
break;
case 'c':
parseCosine();
break;
case 't':
parseTangent();
break;
case 'h':
help();
break;
case 'e':
flag=false;
break;
default:
error();
break;
}
}
return 0;
}