+ 1

ISBN checker

Im having trouble with not including '-' or ' ' when inputing an 10 sigit ISBN This is my code #include <iostream> #include <string> #include <cmath> using namespace std; int main() { cout << "Enter digits of an ISBN-10" << endl; string ISBN; getline(cin, ISBN, '\n'); int d10 = (ISBN[0] * 1 + ISBN[1] * 2 + ISBN[2] * 3 + ISBN[3] * 4 + ISBN[4] * 5 + ISBN[5] * 6 + ISBN[6] * 7 + ISBN[7] * 8 + ISBN[8] * 9); if (d10 % 11 == 0) { cout << ISBN << " is valid" << endl; } else { cout << ISBN << " is invalid" << endl; } for (i = 0; i < 9; i++) system("pause"); return 0; }

28th Mar 2020, 3:30 PM
AKIA GABRIEL TRINIDAD
AKIA GABRIEL TRINIDAD - avatar
4 Answers
+ 6
ISBN is normally represented by a GTIN-13 code, which was formerly called EAN-13. So ISBN has the same rules for verifying / creating the checkdigit. As already mentioned, you have to remove spaces and dash signs from the number to calculate the check digit. You can find more information about calculating the check digits in a PDF from the GS1 Organisation, which has the world wide responsibility for most barcodes on consumer products. https://www.gs1.org/sites/default/files/docs/barcodes/GS1_General_Specifications.pdf From page 466 onwards you can find some descriptions about check digit calculation. I have done some weeks ago a check digit calculator for GTIN-13 in python and published it on Sololear.
29th Mar 2020, 10:09 AM
Lothar
Lothar - avatar
+ 3
I think you need to review the link below, it seems the way you multiply was incorrect. For 10 character ISBN, the position (multiplier) starts from 10 down to 1. In here it seems you start from 1 up to 10 (rather 1 to 9). https://www.instructables.com/id/How-to-verify-a-ISBN/ And you need to convert a numeric char into a number before multiplying the number (from conversion) with position. To convert a char '9' -> number 9, you can subtract the numeric digit by '0'. Also check that N number of characters in ISBN input string are numerical. I mean, skip and ignore dash '-', and space ' '. These are non numeric and useless. P.S. Please save that code in SoloLearn and share the code link instead. It's easier for those who wanted to check the code 👍
28th Mar 2020, 5:00 PM
Ipang
+ 2
Im new to this and im having a hard time on how to apply converting a num char to a number... Ive been getting errors as i use other ways. Ive tried to_string and string numeric = ISBN.c_str(); I was instructed to finish this for our homework and this got me going on for a while..
29th Mar 2020, 11:31 AM
AKIA GABRIEL TRINIDAD
AKIA GABRIEL TRINIDAD - avatar
+ 2
About converting a numeric char to a number (e.g. int), you can try int number = ch - '0'; Where <ch> is a numeric char. char '0' ASCII value is 48, so to get a 0 (zero -> int) you need to subtract the numeric char value with 48 (char '0').
29th Mar 2020, 4:14 PM
Ipang