Creation of an EAN-13 barcode generator? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Creation of an EAN-13 barcode generator?

Let's say we have an int with 12 digits. I'll call that int "myCode". Let's say that the value that this int has, is this: 520142909971 From (and including) the 2nd digit, I want to add every other digit. So, I need to store in another int the sum of the digits 2+1+2+0+9+1 and then multiply it by 3 (therefore to get the result of 15 times 3 = 45). How would I do that? For those who know more, yes, I am trying to build a code for the calculation of EAN-13 barcodes and to produce a checksum 13th digit.

1st Dec 2017, 8:37 PM
Dimitris Petrakis
Dimitris Petrakis - avatar
1 Answer
0
Try using this function: int checksum (long long Code) { int d; int sum=0; while(Code!=0) { d=Code%10; // Get the last digit. sum += d; Code /= 100; // Remove the last two digits } return sum*3; }
2nd Dec 2017, 3:35 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar