djelad1

Untitled

Nov 19th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. switch (option)
  2. {
  3. case 13:
  4. {
  5. int identityCard = 0, rightPartOfTheNumber = 0, checkDigit = 0, sum = 0, i = 0, counter = 0;
  6. bool doubleOrOddDigit = true, isSumTrue = true;
  7. cout << "please enter your id : ";
  8. cin >> identityCard;
  9. checkDigit = identityCard % 10;
  10. identityCard /= 10;
  11. for (i = 0; identityCard > 0; counter++)
  12. {
  13. rightPartOfTheNumber = identityCard % 10;
  14. if (doubleOrOddDigit)
  15. {
  16. rightPartOfTheNumber *= 2;
  17. sum += rightPartOfTheNumber % 10 + rightPartOfTheNumber / 10;
  18. }
  19. else
  20. sum = sum + identityCard % 10;
  21. identityCard /= 10;
  22. doubleOrOddDigit = !doubleOrOddDigit;
  23.  
  24. }
  25. if ((sum + checkDigit) % 10 != 0)
  26. {
  27. isSumTrue = false;
  28. }
  29. if (isSumTrue)
  30. cout << "you wrote correct id \n";
  31. else
  32. cout << "you wrote incorrect id \n";
  33. break;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment