-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
115 lines (96 loc) · 3.46 KB
/
main.cpp
File metadata and controls
115 lines (96 loc) · 3.46 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
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
#include "difference.hpp"
#include "sum.hpp"
int main() {
int stop = 0;
while (stop == 0) {
cout << "-----------------------MENU------------------------\n";
cout << "1. Sum of Two Integers of Optional Base.(2 <= base <= 10)\n";
cout << "2. Difference of Two Integers of Optional Base.\n";
cout << "---------------------------------------------------\n";
int option;
cout << "Choose option: ";
cin >> option;
switch (option) {
case 1:
{
int x, y;
int base;
cout << "Enter the base: ";
cin >> base;
if(2 <= base && base <= 10){
cout << "Enter the 1st number: ";
cin >> x;
cout << "Enter the 2nd number: ";
cin >> y;
while(checkValid(x,y,base))
{
cout << "Input Digits Should Be Smaller Than The Base.\n";
cout << "Enter the 1st number: ";
cin >> x;
cout << "Enter the 2nd number: ";
cin >> y;
}
stack<long> s = sumofBase(x,y,base);
cout << "Result: ";
printStack(s);
}
else
{
string a, b;
cout << "Enter 1st number: ";
cin >> a;
a = upperCase(a);
cout << "Enter 2nd number: ";
cin >> b;
b = upperCase(b);
while(!checkValid_36(a,b,base))
{
cout << "Input Digits Should Be Smaller Than The Base.\n";
cout << "Enter the 1st number: ";
cin >> a;
a = upperCase(a);
cout << "Enter the 2nd number: ";
cin >> b;
b = upperCase(b);
}
stack<char> s;
s = sumOfBase_36(a, b, base);
cout << "Result: ";
printStack(s);
}
cout << "Stop? (1 - YES, 0 - NO): ";
cin >> stop;
break;
}
case 2:
{
string a, b;
int base;
cout << "Input base: ";
cin >> base;
cout << "Input number a: ";
cin >> a;
cout << "Input number b: ";
cin >> b;
string result = difference(a, b, base);
if (result == "NaN") {
cout << "Function 'difference':" << endl;
cout << "Error: Cannot find the difference since the input is invalid." << endl;
return 0;
}
else {
cout << "(a - b)_" << base << " = " << result << "_" << base << endl;
}
cout << "Stop? (1 - YES, 0 - NO): ";
cin >> stop;
break;
}
default:
{
cout << "Option doesn't exist." << endl;
break;
}
}
}
return 0;
}