Need help for carry array Integer operator+ function

I have the code:
LargeInt LargeInt:: operator+(LargeInt &other)
{

int carry = 0;
int temp = 0;
LargeInt ret;


for (int i = 0;i <length;i++)
{
temp = info[i] + other.info[i] + carry;
ret.info[i] = temp % 10;
carry = temp/10;
if (carry > 0)
ret.info[i++] = carry;
}
return ret;
}

When I run it. and I type the two or more number. its only adding the first number.and not carry the integer. for example: I adding 9 and 9 it show 1 but not 18. how can I fix it
Can u please show the complete code
The if (carry > 0) ret.info[i++] = carry; within the loop makes no sense.

Your code, with code tags and one tiny clarification:
1
2
3
4
5
6
7
8
9
10
11
int carry = 0;
for ( int i = 0;i <length; i++ )
{
  temp = info[i] + other.info[i] + carry;
  ret.info[i] = temp % 10;
  carry = temp/10;
  if (carry > 0) {
    ret.info[i] = carry;
    ++i;
  }
}

Lets to 18 + 29:
1. ret[0] = (8 + 9 + 0) % 10; // lines 4-5
2. carry = 1
3. ret[0] = 1 // line 8
// next iteration
4. ret[2] = (1 + 2 + 1) % 10; // lines 4-5
5. carry = 0

The if-clause on step 3 both overwrites ret[0] and makes you hop over ret[1].


Is the LargeInt::length a constant?
I.e. do this and other (and all other LargeInts have same lenght?
What if there is carry from the ret[lenght-1] assignment?
The name "LargeInt" implies that such case is not an overflow error and the class will somehow process and store the "unpreceedingly large" int.
Topic archived. No new replies allowed.