-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
38 lines (31 loc) · 1.05 KB
/
main.cpp
File metadata and controls
38 lines (31 loc) · 1.05 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
#include <iostream>
#include <string>
#include <limits>
#include "./string_calculator.h"
using std::cout, std::endl, std::cin;
using std::string;
int main() {
cout << "String Calculator" << endl;
cout << "\"q\" or \"quit\" or ctrl+d to exit" << endl;
string input;
while(true){
cout << ">> ";
getline(cin, input);
if(input == "q" || input == "quit")
break;
string num1, num2;
if(input.find('+') != string::npos){
num1 = input.substr(0,input.find('+') - 1);
num2 = input.substr(input.find('+') + 2);
cout << endl << "ans =" << endl << endl << " ";
cout << add(num1, num2) << endl << endl;
}
else if(input.find('*') != string::npos){
num1 = input.substr(0,input.find('*') - 1);
num2 = input.substr(input.find('*') + 2);
cout << endl << "ans =" << endl << endl << " ";
cout << multiply(num1, num2) << endl << endl;
}
}
cout << endl << "farvel!" << endl << endl;
}