Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 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 = 8;
  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[13];
  30. int BarCode1[13];
  31. cout << "Wprowadz swoj kod" << endl;
  32. cin >> BarCode;
  33.  
  34. for (int i = 0; i < 13; i++)
  35. {
  36. BarCode1[i] = BarCode[i] - '0';
  37. }
  38.  
  39. for (int i = 1; i < Size1; i++)
  40. {
  41. S += ((2 - pow(-1, i)) * BarCode1[i - 1]);
  42. }
  43. ControlNumber = 10 - (S % 10);
  44. cout << BarCode1[Size1-1] << endl;
  45. cout << S << endl;
  46. cout << ControlNumber << endl;
  47. if (ControlNumber == BarCode1[7])
  48. {
  49. cout << "\n Valid bar code";
  50. }
  51. else
  52. {
  53. cout << "\n Invalid bar code";
  54. cout << "\n Valid Barcode is: " << endl;
  55. BarCode1[7] = ControlNumber;
  56.  
  57. for (int i = 0; i < 8; i++)
  58. {
  59. cout << BarCode1[i];
  60. }
  61. }
  62.  
  63. case 2:
  64. //CheckIfCodeValid(13);
  65. case 9:
  66. exit(1);
  67. default:
  68. break;
  69. }
  70. }
  71. }
  72.  
  73. void CheckIfCodeValid(int Size)
  74. {
  75.  
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement