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;
LVL 1
edvinsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.