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 didnot find the behaviour you said please recheck

I receive 123456786.

Any explanation?

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.

I don't understand. But I don't have any other arrays, this is all of code.

if so i donot have an explanation

this is what i got can you please take screen shoot from the code like this
Link.........

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

But how pow() can affect on decrementing my sum?

did it solve the problem?

Nope, it didn't.
I replaced 10 with 10.0 and it keeps doing the same.

Yes, it was problem with pow().

I made my own pow() function and it worked perfectly.

Thanks a lot!

( check the code and output )

you are welcome

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.