Hi,

What's wrong with this code:

//Comments explain what I check
int Array[9]={1,2,3,4,5,6,7,8,9};
    int Integer=0;
    int i=8,n=0;

    for(int x=0;x<9;x++)
    cout<<"array="<<Array[x]<<endl;                   //Are all members ok?

    for(int exp=0;i>=0;i--){
            Integer+=Array[i]*pow(10,exp);
            cout<<"Integer1="<<Integer<<endl;         //Is Integer being summed fine?
            exp++;
            }
            
            cout<<"Integer="<<Integer<<endl;

Program's function is to create an integer from array ( for example: if array has 1,2,3; it need to make integer 123 ).

The problem is terrible:

If I have 3-4 members of array my result will decrement during 3rd summing.
If I have 5-6 members result will decrement during 3rd and 5th summing.
If I have 7 members result will decrement during 5th summing.
If I have 8 members result will decrement during 3rd summing.
If I have 9 members result will decrement during 3rd, 5th and 9th summing.

( I haven't removed cout-checks so you can see what I do )

What is the problem??

Thanks a lot, I'm lost.

i didnot find the behaviour you said please recheck

I receive 123456786.

Any explanation?

Edited 5 Years Ago by MrEARTHSHAcKER: n/a

maybe you had another array if any element contains more than single digit the result will not be true and if any element is zero the result will be false also.

this code will not compile because of ambiguaty in pow so how did it ran?
any way try to

Integer+=Array[i]*pow(10.0,exp);

and make sure that it will build

This question has already been answered. Start a new discussion instead.