I am a 2nd year student and I am working on a Technical Programming project where we are asked to solve a problem about ISBNs. I am now at a step where I have to verify with someone else that my pseudocode works, hence I joined the forum. Basically here I am validating that an ISBN is correct. This is how I made my pseudocode using knowledge from other sites as well. To give some background knowledge, an ISBN is divided into 4 parts seperated by a hyphen: group code, publisher's code, number of the book title and the check digit. example of a 10 digit ISBN: 0-14-012499-3. You can use this or any ISBN of a text book you have to validate my pseudocode
Display 'Enter a 10 character ISBN'
GET ISBN
total = 0;
FOR counter GOES FROM 1 TO 9//represents the 9 characters excluding the check digit
thisDigit = character 'counter' of 'ISBN';//each character of the ISBN
total = total + thisDigit;//checks the 9 characters of ISBN
END FOR
checkDigit = 10th character of ISBN;
remainder = 11-(total / 11);// this is the formular to calculate the check digit
calculatedCheckDigit = 11 - remainder;
IF(calculatedCheckDigit = 10)
calculatedCheckDigit = 'X';
END IF
IF(calculatedCheckDigit = checkDigit)
Display('ISBN is valid')
Thank you
Loading
Sam HobbsPosted Mar 30, 2011, 4:47 PM
Pasting 0+7+3+5+6+1+5+7+9 into the Windows Calculator gives 43. Divide that by 11 gives 3.9090909090909090909090909090909.
Are we supposed to round that off so it becomes 4 or simply truncate so it becomes 3?
11 - 4 = 7
11 - 7 = 4
4 != 9
The ISBN is valid but either I did not follow the pseudocode properly or the pseudocode is invalid.
Did you try the pseudocode yourself before posting here? If you can show your iintermediate results as I did then that will help.
Avuya MxoliPosted Mar 30, 2011, 5:49 PM
Avuya MxoliPosted Mar 30, 2011, 5:27 PM
VulpesPosted Mar 30, 2011, 3:22 PM
Using the number you gave as an example:
remainder = 11 - (30/11); // which using integer arithmetic is 9
calculatedCheckDigit = 11 - 9; // which is 2 but the answer should be 3
I'd express it instead as:
remainder = total modulo 11; // which is 8 when total = 30
Apart from that, it looks OK to me.