Advertisement
Guest User

Untitled

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