this syntax look strange:

if (!mod_cksum==3){

if(!27==sum){

i guess you mean:

if (mod_cksum!=3){

if(27!=sum){

ike

Solved

Posted on 2006-04-19

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;

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,sz

nCharsReceived2 = GetWindowText(hWndRight,sz

nCharsReceived3 = GetWindowText(hWndLeft2,sz

// 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;

5 Comments

this syntax look strange:

if (!mod_cksum==3){

if(!27==sum){

i guess you mean:

if (mod_cksum!=3){

if(27!=sum){

ike

Title | # Comments | Views | Activity |
---|---|---|---|

Modify static variables within a class in VC++ | 3 | 85 | |

TTimer no longer functioning | 7 | 64 | |

Why would downloading El capitan OSX update be troublesome e.g timeout many many times?? | 11 | 376 | |

Using Diagnostic tools in VS2015: Unresoved allocations | 19 | 28 |

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**17** Experts available now in Live!