OK, Everything is compiling just fine. The only problem I'm getting is the output after the math is not correct. The idea of the program is to store integers larger than what the int variable can store in a string. It is an assignment for school. Any help would be appreciated! Thanks!
I don't really need 500 digits of precision. I was just getting a little crazy there trying to figure out why it was outputing a negative number when I add two integers of 18 digits. Does that make sense? The idea of the program is to store values in a string (values to large to fit in an integer variable) and still be able to perform math on them (that is why I convert the strings into double before i perform the math. So when I multiply two values that are over 10 digits (the max a variable of int can hold right?) I can output them in regular number notation (not scientific). Sorry if I'm confusing anyone. Any ideas on how to accomplish that goal, if this one isn't appropriate?
36
+75
---
6+5=11, but we can keep only one digit, so we have to store the other
1
36
+75
---
1
1+3+7=11. Again over the top
1
36
+75
---
11
1+0. Finally a direct fit
36+75=111
That was like each digit would be a separate integer. Same principle works for BigInts too. You have to recognize when things will overflow, and move the surplus to the next "part" of the BigInt.
For example, take 9 left-most digits from a string and store them into int. Take next 9 digits into second int. Next ...
Ok, I have been thinking about the problem at hand...and I have only succeeded in confusing myself... How does one go about reading the string and adding by character and splitting where it overflows? I was thinking read the string, split it into 8 digit segments(have a better idea?), convert each segment of the first integer to a int, then convert each segment of the second integer to an int, then adding the segments together, converting the added segments back to a string, then appending the strings together. Does that make sense to anyone else lol?
So if I entered: 123456789123456789 and 123456789123456789
I would split the first input to 12345678, 91234567, 89
Then split the second input to 12345678, 91234567, 89.
Then add 12345678 + 12345678 = 24691356
then add 91234567 + 91234567 = 182469134
then add 89 + 89 = 178
Then take 24691356 and append 182469134 to it, then append 178 to that. To come up with 24691356182469134178
Is that logic correct? Sorry, my brain is fried lol.
Edit: Ok, just remembered I had a calculator lol, my logic is good. So how do I split the string like that?