Here I've got a sad multiplication function that is part of a large bigint calculator class. the arr is a pointer to a resizable array class(get and set are members of that class). When I use this I can mulitply large numbers only by one digit, if more digits )example 12*214 i get 428 cause its only multiplying 214 by the 2 in twelve. I understand why that is happening, I'm just not sure that I can fix it before the assignment is due tomorrow. Any help? Thanks!
void multiply(const bigint &A)
{
int carry=0;
for(int i=size-1;i>=0;i--)
{
int result = arr->get(i)*A.arr->get(size-1)+carry;
arr->set(i,result%10);
carry=result/10;
}
}
int main()
{
a.assign("214");
b.assign("12");
a.multiply(b);
a.print();
void add_pos(const bigint &A) //add big ints
{
int carry=0;
for(int i=size-1;i>=0;i--)
{
int result = arr->get(i)+A.arr->get(i)+carry;
arr->set(i,result%10);
carry=result/10;
}
}
I understand what you are saying but I'm just not sure how to code it.
thanks
What else do you have?
Could you please post the Function declerations of all methods?
Also, you might want to copy a bit of data.
And you have to resize your data a little bit. a multiplication of 999*999 results in a 6-digit value, not a 3-digit one.
No I got alot of errors with the referencing of the methods of the other class for temp 1 and 2.My fault though, I should have sent you the full code first
Sorry, I'll use it from now on.
I'm still getting errors on lines 14,18, and 20
14 says ( member reference type bigint is not a pointer)
18 says ( use of undeclared identifier temp2)
20 says ( member reference type bigint is a pointer
if(size - shift - (i - size-1) >= 0)
temp2.arr->set(size - shift - (i - size-1), result%10);
elsebreak;
It looks like this now...
I have a hard time using your SaveArray class for that example because we loop from the end to the beginning and so the resizing mechanism does not work