Teen Programmers Unite  
 

 

Return to forum top

using C for an ISBN check digit

Posted by muffdust [send private reply] at November 20, 2001, 11:45:02 AM

I am writing a program that reads an ISBN number checks if the value is numeric and if there are any charcaters it is only alowed to be an X or x in the 10th digit...
i have done all these except the check digit... (digit one * 10) + (digit two * 9) + ....(digit 10 * 1 ) modulus 11...

i cant seem to code it properly, any pointers please?


this is what i have so far

#include <stdio.h>
#include <string.h>
int test(char *str);
int main()
{
int YorN;
char str[10];


puts("Enter the ISBN number->\n");
puts("Please note that any ISBN number entered over 10 char will be truncated\n");
gets (str);

puts("The input was->");
puts(str);
printf("Is this correct? please enter y or n");
scanf("%c", &YorN);

if (YorN == 'y')
{
test(str);
}

else if(YorN == 'n')
{
/*loop to the start*/
}

return 0;

}


int test(char *str)
{
int i;

scanf("%c%c", &str[0], &str[1]);
scanf("%c%c", &str[2], &str[3]);
scanf("%c%c", &str[4], &str[5]);
scanf("%c%c", &str[6], &str[7]);
scanf("%c%c", &str[8], &str[9]);

if ((str[9] == 'x') || (str[9] == 'X') || (isdigit(str[9])) )
{
printf("X is in correct location");
}
else
{
puts("INVALID, x is not in correct location");
}

if((isdigit(str[0]))
&& (isdigit(str[1]))
&& (isdigit(str[2]))
&& (isdigit(str[3]))
&& (isdigit(str[4]))
&& (isdigit(str[6]))
&& (isdigit(str[7]))
&& (isdigit(str[8])))
{
printf("string is numeric");
}
else
{
printf("is not numeric");
}


return 0;
}

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.