Hello,

Wondering if you can help me.. I have a variable, that each time needs to multiply by 2 (I know, it sounds simple.. I'm probably being an idiot) but it works like this:

LOOP 1
offsetX = 0;
offsetY = 0;

LOOP 2
offsetX = 2;
offsetY = 0
LOOP 3
offsetX = 4;
offsetY = 0;

Here is the code:

[code]

int offsetX = 0;
int offsetY = 0;
for(int i=0; (i < (4*4)); i++)
{
for(int i=0; (i < subRow); i++)
{
for(int j=0; (j < subCol); j++)
{
int var1 = offsetX + j;
int var2 = offsetY + i;

            row = offsetX*2;
            col= offsetY*2;

            cout << row << col << endl;
        }
    }

[/code]

Any ideas? Thanks :)

Edited 4 Years Ago by phorce: code tags don't work?!?1

You have 3 for loops that are nested one within the other, 2 of which use i as the variable. Don't duplicate the variable name if you have a 3 deep nested loop or, as in your case, don't use a 3 deep nested loop.

OffsetX doesn't really double each time in your example. The change from zero to 2 is a special case. So if j is 0, OffsetX is 0, else OffsetX is 2^j

Hey,

Thanks for your replies..

Basically, I'm trying to split a matrix into blocks..

0 1 0 1
1 1 0 0
1 0 0 0
0 0 0 0

M1 = {
0 1
1 1
}

M2 = {

0 1
0 0
}

M3 = {
1 0
0 0
}

M4 = {
0 0
0 0
}

now I have two variables:
offsetX = 0;
offsetY = 0;
and using a formular I can calculate and it works well
apart from the very last block.. Here is the sequence of numbers:

0145
2367
891213
26273031 (This is wrong)

This is the code so far:

  Matrix subMatrix(subRow * subCol, 0);
    int offsetX = 0;
    int offsetY = 0;
    for(int q=0; (q < (4)); q++)
    {
        for(int i=0; (i < subRow); i++)
        {
            for(int j=0; (j < subCol); j++)
            {
                int row = offsetX + j;
                int col = offsetY + i;
                int sum = subRow+subCol;
                cout << row+col*sum;

            }
        }
        offsetX = offsetX*3+2;
        cout << endl;
    }
    cout << endl;

Any ideas?? Thanks

Edited 4 Years Ago by phorce: Updated

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