i'm trying to add two arrays and i can't seem to get my carry to work in my add function.
for example, if array a has 1,2,3, and array b has 5,6,7, i should get 690. but since there is a flaw here, i get 680. why?
can anyone point out the flaw in my logic?
bool add (int a[], int b[], int sum[])
{
int x, temp;
for(int x=MAX_DIGITS-1; x>=0; x--) // first index of array is 0 in C/C++
{
sum[x]=a[x]+b[x];
if(temp==1)
sum[x]=sum[x]+1;
if(sum[x]>=10)
{
temp=1;
sum[x]=sum[x]-10;
}
else
{
temp=0;
}
cout<<sum[x]<<" ";
}
if(( x<0 )&&(temp==1)) // = is assignment == is comparison
return false;
else
return true;
}