looping and arrays
- by user1838418
Hi I'm trying to construct a loop to execute 16 states of the 8 4 2 1 code in (C++)
while( condition)
{
double Bubble[16], Bubble1[16];
Bubble[0] = ( a-2 - (b-2) ) + ( c-2 - (d-2)); // represents 0000
Bubble[1] = ( a-2 - (b-2) ) + ( c-2 - (d+2)); // represents 0001
Bubble[2] = ( a-2 - (b-2) ) + ( c+2 - (d-2)); // represents 0010
Bubble[3] = ( a-2 - (b-2) ) + ( c+2 - (d+2)); //represents 0011
.......
Bubble[15] =(a+2 - (b+2) ) + ( c+2 - (d+2)); //represents 1111
}
Is there an easy way of coding using for loops? instead of writing bubble[] every time?
0 stands for -2 and 1 stands for +2. So I have 4 variables and each one need to be incremented and/or decremented. Can this be done using for loop?
Appreciate your help