I finally got a basic Arbitrary-precision system up and running only on addition. I'm now doing one in subtract and the problem is that when doing the "subtracting one from the top number next to you on the left and adding ten to the top digit that is below in value of the bottom digit"(I honestly can't describe it very well, but I think you can interoperate that), it doesn't change the digit that was borrowed from even though I'm using pointers. It does, however, properly add ten if the top digit is too small.
I posted my code for subtraction:
What's wrong?
I posted my code for subtraction:
Code:
void subtractNumbers(int space,int number[], int number2[], int *toStore)
{
int goUp=0;
int *p;
int *q;
int *r;
r=toStore;
for(int digit = (space-1); digit >= 0; digit--)
{
p = &number[digit]; //Grabs the digit
q = &number2[digit]; //Grabs the digit
while(*p < *q) //If the bottom digit is higher than the top digit
{
goUp++; //Checks one digit ahead
p = &number[digit+goUp]; //Goes to the next digit
if(*p!=0) //If the next digit isn't a zero
{
*p-=1; //It'll then subtract one
while(goUp>0) //While there are possibly more digits
{
goUp--; //We'll go down one digit
p = &number[digit+goUp];
if((*p==0) && (goUp > 0)) //If the digit is zero and there are more than one digit to carry over
{
*p=9;
}
if(goUp==0) //Otherwise, add ten.
{
*p+=10;
break;
}
}
break;
}
}
goUp=0;
*r = *p - *q; //Then subtract the number the number
*(toStore + digit) = *r; //Now store the value.
}
}