Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Save my C++

Name: A times B equals F 2011-02-03 9:51

Why doesn't this work? ='[

//Set up nested loops:
    for(int i = 0; i < 3; ++i)
    {
        for(int j = 0; j < 3; ++j)
        {
            //Multiply elements of A * B = C:
            C[j] = A[i] * B[j];

            //Deal with Carry of multiplication:
            if(C[j] > 9)
                C[j+1] += CarryTheOne( C[j] );

            //Add to contiguous answer:
            F[j+i] += C[j];

            //Deal with Carry of addition:
            F[j+i+1] += CarryTheOne( F[j+i] );
        }

}
//--------------------------

int CarryTheOne( int & x )
{
    if(x > 9)
    {
        //get unit element ( < 9 )
        x -= 10;
        //return carry (only ever 1)
        return 1;
    }
    return 0;
}

Name: Anonymous 2011-02-03 9:58

When i input 62 & 123 (well 26 & 321) i get 6526 (well 6256) instead of 7626 (well 6267)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List