#include #include const bool debugging = false; const int size = 30; // I want to make it easy to work with. // Change to something big later. struct bignum { int digit[size]; char sign; // '+' or '-' bool ok; }; // to store the number one thousand six hundred and seventy nine, // 1679, digit[0]=9, digit[1]=7, digit[2]=6, digit[3]=1, all the rest are zero void init(bignum & B) { for (int i = 0; i < size; i += 1) B.digit[i] = 0; B.sign = '+'; B.ok = true; } void print(bignum B) { if (! B.ok) cout << "BAD"; cout << B.sign; bool printed = false; for (int i = size - 1; i >= 0; i -= 1) { int dig = B.digit[i]; if (debugging) cout << "|"; if (dig != 0 || printed || debugging) { cout << dig; printed = true; } } if (! printed) cout << "0"; } void addsmall_is(bignum & B, int N) // _is means "ignoring the + or - sign" // N must be small. { int toadd = N; int position = 0; while (toadd > 0) { int sum = B.digit[position] + toadd; if (sum < 10) { B.digit[position] = sum; toadd = 0; } else { B.digit[position] = sum % 10; toadd = sum / 10; } position += 1; if (position >= size) { B.ok = false; break; } } } void main() { bignum X; init(X); while (true) { print(X); cout << "\n"; char c; int n; cin >> c >> n; if (cin.fail()) break; if (c == '+') addsmall_is(X, n); else cout << "+ is the only thing I know how to do\n"; } }