I think this may be more of a math problem then anything else; the problem is trying to use C++ code to do the math that I need. I'm trying to overload the * operator so I can multiply 2 objects of the same class. The class is called "HugeInt" and it's basically what it is, which allows me to go beyond the 4 billion limit of "double" in a 32-bit machine. But for the life of me I can't figure out how to multiply arrays. The addition part was easy, but multiplication just doesn't want to work for me. Anyway, here is the code

Code:
```
HugeInt HugeInt::operator *( const HugeInt &op2 ) const
{
HugeInt tempMultiply; // temporary result
int carryMultiply = 0;

for ( int i = 29; i >= 0; i-- )
{
tempMultiply.integer[ i ] =
integer[ i ] * op2.integer[ i ] + carryMultiply;

//determine whether to carry a 1
if ( tempMultiply.integer[ i ] > 9 )
{
tempMultiply.integer[ i ] %= 10;  // reduce to 0-9
carryMultiply = 1;
} // end if
else // no carry
carryMultiply = 0;
} // end inner for

return tempMultiply;
}```
If the code is absolutely sloppy, I apologize for that. Thanks for any help

2. Well, not that you've been real specific about what the class is/does, but I'm guessing that HugeInt is an array of 30 digits, and the whole thing strung together represents a number.
If that's the case, say we have two HugeInts (pretending HugeInt has 10 digits, not 30) like this:
Code:
```Host object (this):
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
3   4   5   1   0   6   3   5   2   7

op2:
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
4   5   2   1   5   9   0   1   4   5```
representing 3451063527 and 4521590145, respectively.

By your algorithm, it seems we first loop from the back of the numbers forward. i = 9 in this case. Then we multiply this.integer[9] by op2.integer[9], check to see if we need to carry, and decrement i. Then we multiply this.integer[8] by op2.integer[8], check to see if we need to carry. In the case above, we multiply 7 by 5, and store the result in tempMultiply[9] (checking for carry). Then we multiply 2 by 4, add one for the carry, and assign the result to tempMultiply[8] (checking for carry).

So far tempMultiply[] looks like:
Code:
```[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
?   ?   ?   ?   ?   ?   ?   ?   7   2```
I trust my calculator's answer of 15604294833452141415, (which wouldn't fit in 10 digits anyway, how are you accounting for that in HugeInt?) so something's already wrong with your algorithm.

Is this how we multiply two numbers? I don't think so...

And my assumptions better be right because that post took way longer that I thought it would... [/edit]

3. Well, I wasn't checking to make sure that the numbers would fit into a 30-element array, but I can always add this at a later time after I figure out how to make this algorithm multiply correctly.

You’re absolutely correct about the class. I apologize for not being more specific, but the array does represent a number, whether it was input as a string or as integers, the constructor is able to convert the numbers and write them to the array.

I'm not sure what it is that I'm missing. I know what I want the function to do, which is multiply numbers, but I'm just not sure I'm translating the math correctly into C++ code.

I really appreciate you taking the time in trying to help, Decrypt. Thank you!

4. Well, how do you do multiplication by hand?

E.g. How do you do 21 * 34 on paper?

Your program's logic would be that you'd do 1* 4 = 4, and 2 * 3 = 6, and get an answer of 64.

How would you correctly do the math?

5. I believe the standard way to multiply numbers using paper and pecil goes like that:

Code:
```456 * 789 =
6*789 + 50*789 + 400 *789 =
4734
+  39450
+ 315600
------------
= 359784```
You might need a whole temporary array for HugeInts and an overloaded + operator.

Code:
```for ( int i = 29; i >= 0; i-- ) //don't use magic numbers
//a HugeInt might also have a value that shows how many digits it has```
You'd probably need dynamic containers to store HugeInts. You can easily go over this arbitrary limit.