-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
65 lines (52 loc) · 1.27 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
#include <iostream>
#include "version.h"
#include "bigint/bigint.h"
enum bigintOperator {
PLUS, MINUS
};
int run_cli() {
std::string operation, x,y;
bigintOperator op;
std::cout << "enter operation" << std::endl;
std::cin >> operation;
if (operation.empty()) {
std::cerr << "empty operation name" << std::endl;
return 1;
}
switch (operation[0]) {
case '-':
op = MINUS;
break;
case '+':
op = PLUS;
break;
default:
std::cerr << "wrong operation name provided, '+' and '-' are supported for now" << std::endl;
return 1;
}
std::cout << "enter first number:" << std::endl;
std::cin >> x;
std::cout << "enter second number:" << std::endl;
std::cin >> y;
bigint a;
bigint b;
try {
a = bigint(x);
b = bigint(y);
} catch (const char * msg) {
std::cerr << "exception caught while trying to read the argument" << std::endl;
std::cerr << msg << std::endl;
return 1;
}
std::cout << "result: "<< std::endl;
if (op == PLUS) {
std::cout << a + b << std::endl;
} else { // op == MINUS
std::cout << a - b << std::endl;
}
return 0;
}
int main() {
std::cout << "bigint-cli, version=" << git_version() << ", revision=" << git_revision() << std::endl;
return run_cli();
}