• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

My Loop NEVER return false

I have three edit boxes that represent a safe's combination.

I need to add up all the numbers and make sure the numbers = 27.
(This part appears to be working fine).

I also need to make sure that:
(FIRSTNUMBER(ascii) - 40) + (SUM_OF_ALL_NUMBERS % 10) % 7 = 3

and it's not working! I think this is failing on CHECK TWO.

My debug MessageBox is never getting called, and the function always returns true.

Any ideas?



       // Get LEFT, RIGHT, LEFT2 Edit Controls
       HWND hWndLeft1      = GetDlgItem(hWndDlg, IDC_LEFT1);
       HWND hWndRight      = GetDlgItem(hWndDlg, IDC_RIGHT1);
       HWND hWndLeft2      = GetDlgItem(hWndDlg, IDC_LEFT2);

       int nCharsReceived1;
       int nCharsReceived2;
       int nCharsReceived3;

       char szLeft1[3];
       char szRight1[3];
       char szLeft2[3];
       char szcombo[80];

       nCharsReceived1       = GetWindowText(hWndLeft1,szLeft1,3);
       nCharsReceived2       = GetWindowText(hWndRight,szRight1,3);
       nCharsReceived3       = GetWindowText(hWndLeft2,szLeft2,3);

      // Make sure there are numbers in every box
      // otherwise, return FALSE.
      if(nCharsReceived1==0)
            return false;

      if(nCharsReceived2==0)
            return false;

      if(nCharsReceived3==0)
            return false;

       // Now we have to concat all three text boxed
       // to come up with a 6 digit combination
       strcpy (szcombo,szLeft1);
       strcat (szcombo,szRight1);
       strcat (szcombo,szLeft2);
      
      // Now get the SUM as pcgabe from EE showed me
      int sum = szcombo[0]-'0';
      for (int i=1; i<strlen(szcombo); i++){
          sum+=szcombo[i]-'0';
      }

      // CHECK ONE
      if(!27==sum){
            return false;
      }

      // CHECK TWO
      // 2: (50 - 40) + (27 % 10) % 7 = 3
      int mod_cksum;
      mod_cksum = ((szcombo[0]- 40) + (sum % 10)) % 7;
      if (!mod_cksum==3){

            sprintf(DEBUG_BUFFER, "%i", mod_cksum);
            MessageBox(hWnd, DEBUG_BUFFER, TEXT("Debug"),0);

            return false;
      }

      // CHECK THREE
      // TO DO:

      // LOOKS LIKE THEY PASSED ALL THE TESTS
      // SET DONE FLAG and RETURN TRUE

       done_array[2]=1;
         return true;
0
edvinson
Asked:
edvinson
  • 3
  • 2
1 Solution
 
ikeworkCommented:
hi edvinson,


this syntax look strange:

if (!mod_cksum==3){
if(!27==sum){


i guess you mean:

if (mod_cksum!=3){
if(27!=sum){


ike
0
 
edvinsonAuthor Commented:
Ugh....

i can thank javascript and php for getting in that habit.

thanks. works fine now.
0
 
ikeworkCommented:
you can simplify something in CheckTwo

     // CHECK ONE
     if(27!=sum){
          return false;
     }

     // CHECK TWO
     // 2: (50 - 40) + (27 % 10) % 7 = 3
     // we know sum == 27,  so:  (27 % 10)) % 7 == 0
     int mod_cksum = szcombo[0]- 40;
     if (mod_cksum!=3){


ike
0
 
edvinsonAuthor Commented:
cool! thanks for the tip! I'd give you more points but it won't let me, sorry.

0
 
ikeworkCommented:
you're welcome ... glad to help :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now