Advertisement
Guest User

Untitled

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