Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. void CheckIfCodeValid( int siza);
  7.  
  8. int main()
  9. {
  10. int Choice;
  11.  
  12.  
  13. while (1)
  14. {
  15. int ControlNumber = 0;
  16. long S = 0;
  17. int CNumber = 0;
  18. const short Size1 = 13;
  19. const short Size2 = 13;
  20. cout << "Menu" << endl;
  21. cout << "Wybierz rodzaj kodu kreskowego" << endl;
  22. cout << "\t1. EAN-8."
  23. << "\n\t2. EAN-13."
  24. << "\n\t9 By zakonczyc program"<<endl;
  25. cin >> Choice;
  26. switch (Choice)
  27. {
  28. case 1:
  29. char BarCode[Size1];
  30. cout << "Wprowadz swoj kod" << endl;
  31. cin >> BarCode;
  32.  
  33. for (int i = 1; i < Size1; i++)
  34. {
  35. S += ((2 - pow(-1, i)) * BarCode[i - 1]);
  36. }
  37. ControlNumber = 10 - (S % 10);
  38.  
  39. cout << BarCode[Size1-1] << endl;
  40. cout << S << endl;
  41. cout << ControlNumber << endl;
  42. CNumber = BarCode[Size1-1] - '0';
  43. cout << CNumber;
  44. if (ControlNumber == CNumber)
  45. {
  46. cout << "\n Valid bar code";
  47. }
  48. else
  49. {
  50. cout << "\n Invalid bar code";
  51. cout << "\n Valid Barcode is: " << endl;
  52. BarCode[7] = ControlNumber;
  53. for (int i = 0; i < 8; i++)
  54. {
  55. cout << BarCode[i];
  56. }
  57. }
  58.  
  59. case 2:
  60. //CheckIfCodeValid(13);
  61. case 9:
  62. exit(1);
  63. default:
  64. break;
  65. }
  66. }
  67. }
  68.  
  69. void CheckIfCodeValid(int Size)
  70. {
  71.  
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement