looping and arrays

Posted by user1838418 on Stack Overflow See other posts from Stack Overflow or by user1838418
Published on 2012-12-07T16:57:02Z Indexed on 2012/12/07 17:05 UTC
Read the original article Hit count: 147

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about c++

Related posts about arrays