Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Find the necessary number of operations (highest number of digits)
- int calcCount;
- if (currentSize > x.currentSize)
- calcCount = currentSize;
- else
- calcCount = x.currentSize;
- //make the new return array
- char sum[100];
- //perform the calculations starting at the least significant digit
- int result;
- int carry = 0;
- int finalNull;
- cout << "calcCount is " << calcCount << endl;
- for (int i = 0; i < calcCount; i++) {
- int result = static_cast<int>(number[MAXSIZE - i]) + static_cast<int>(x.number[MAXSIZE - i] + carry);
- if (carry != 0)
- carry = 0;
- if (result > 10) {
- result = result % 10;
- carry = 1;
- }
- sum[MAXSIZE - i] = result;
- finalNull = i + 1;
- }
- sum[MAXSIZE - finalNull] = '\n';
- return sum;
Add Comment
Please, Sign In to add comment