Question
I have trouble getting the function parameters right. Here's the question and outline of the program: The International Standard Book Number (ISBN) is a unique, numerical commercial book identifier. The ISBN is 13 digits long if assigned after January 1, 2007. The last digit of the thireen-digit ISBN is called check digit, which is used to verify if an ISBN is a valid ISBN. The following describes the way to calculate the check digit. The calculation of an ISBN-13 check digit begins with the first 12 digits of the 13-digit ISBN (thus excluding the check digit itself). 1) Each digit, from left to right, is alternately multiplied by 1 or 3, 2) those products are summed and calculated modulo 10 to give a value ranging from 0 to 9. 3) the value is subtracted from 10, that leaves a result from 1 to 10. 4) A zero (0) replaces a ten (10), so, in all cases, a single check digit results. For example, the ISBN-13 check digit of 978-0-306-40615-? is calculated as follows: s = 9
Explanation / Answer
#include int i; int checkx(int isbn[10]) { for(i = 0; i < 10; i++) { if(isbn[i] == 'X') break; } return i; } int checko(int isbn[10]) { for(i = 0; i < 10; i++) { if(isbn[i] == '?') break; } return i; } int main() { int isbn[10], th1, th2, sum = 0, j; char ten = 'X'; printf(" Enter the ISBN Code: "); scanf("%s", isbn[10]); th1 = checkx(isbn[10]); th2 = checko(isbn[10]); if(th1 > th2) { for(i = 0; i