-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.cpp
48 lines (45 loc) · 1.21 KB
/
calculator.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
#include "calculator.h"
#include <iostream>
#include <string>
using namespace std;
void help(){
cout << "List of options:" << endl;
cout << "--help -h Displays help message" << endl;
cout << "--add -a Adds two numbers" << endl;
cout << "--sub -s Subtracts two numbers" << endl;
cout << "--mul -l Multiply two numbers" << endl;
cout << "--div -d Divides two numbers" << endl;
}
void Calculator(string str, char delimiter){
string o1 = "";
string o2 = "";
bool flag = false;
for (int i = 0; i < str.length(); i++){
if (str[i] == delimiter){
flag = true;
continue;
}
if (!flag){
o1 += str[i];
}
if (flag){
o2 += str[i];
}
}
if (delimiter == '+'){
cout << str << endl;
cout << stof(o1) + stof(o2) << endl;
}
if (delimiter == '-'){
cout << str << endl;
cout << stof(o1) - stof(o2) << endl;
}
if (delimiter == '*'){
cout << str << endl;
cout << stof(o1) * stof(o2) << endl;
}
if (delimiter == '/'){
cout << str << endl;
cout << stof(o1) / stof(o2) << endl;
}
}