you need to have a user defined type for performing arithmetic operations (atleast a plus) on integers with large precision. either write a big_integer class or use a library
eg:class bigint from the LiDIA library ( http://www.cdc.informatik.tu-darmstadt.de/TI/LiDIA/ )
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
C++ is extremely limited in the values you can use. For example, the int data type is only guaranteed to hold the values -32,767 to 32,767. A large integer like 9999999999999999999999999 can't be stored in a single variable of any type. So you get around it in one of two ways.
The first way is manually. You store pieces of the value in multiple variables and write functions that handle the math between those variables. This is tough, and I don't recommend it if you're not confident in your C++ abilities.
The second way is by using a library that does the manual stuff for you. This one for instance. The problem with this solution is that you have to learn a library and now you're bound to something that isn't standard.
Now, from the looks of your problem, I'd say you've been given an assignment to manually perform addition on large integers. But it's hard to be sure because you've been rather vague in the requirements. Can you describe your assignment in a little more detail? There's a possibility that you simply asked the wrong question and that's why the answers are confusing you.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Do you mean add the digits together? Or are you really going to get multiple huge numbers that need to be added together? Show us some sample input and the expected output.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
So do you know how to perform addition on paper?
You know, start at the 'units' column of both numbers, add them together and if necessary propagate a 'carry' into the addition of the 'tens' column.
When you understand that bit, then think about how you would do the same with a stack - pop the units off two input stacks, add them and push the result onto another stack.
From there, writing the code should be pretty easy.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
>it is bringing in such a large integer
I honestly don't see what the problem is. Have you even bothered to google for how it might be accomplished? Have you even read the previous posts? Telling you to first plan how you would do it on paper then just apply it to your model/ program?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
> it is bringing in such a large integer
What's so hard about reading a string, then extracting each digit, and pushing the value of the digit onto a stack?
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Read the number as a string and then index it to get each digit. You're making this way harder than it needs to be.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401