Thread: isbn number.

  1. #1
    Registered User
    Join Date
    Oct 2007
    Location
    Behind you
    Posts
    2

    isbn number.

    i need help with the error

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define size 11
    
    int check(int a[size]);
    
    int main()
    {
       char a[size],
            i,
            x;
    
       printf("Enter 10 character ISBN number (Do Not Separate ISBN Characters With"
              "Spaces): \n\n");
    
       for(i=0; i<=10; i++)
          a[i]=getchar();
    
       x=check();
    
       if(x==a[9])
          printf("ISBN is valid.");
       else
          printf("ISBN is invalid");
    
    
       system("PAUSE");
       return 0;
    }
    
    int check()
    {
       int sum,
           x,
           y=0;
    
       for(i=0; i<=9; i++)
          a[i]=a[i]-48;
       for(i=0; i<=9; i++)
       {
          x=y+(i+1)*a[i];
          y=x;
       }
       sum=x%11;
       return sum;
    }

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    what errors are you getting? More details would be nice.

  3. #3
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    look at the prototype for check.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by xxbleh View Post
    i need help with the error

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define size 11
    
    int check(int a[size]);
    
    int main()
    {
       char a[size],
            i,
            x;
    
       printf("Enter 10 character ISBN number (Do Not Separate ISBN Characters With"
              "Spaces): \n\n");
    
       for(i=0; i<=10; i++)
          a[i]=getchar();
    
       x=check();
    
       if(x==a[9])
          printf("ISBN is valid.");
       else
          printf("ISBN is invalid");
    
    
       system("PAUSE");
       return 0;
    }
    
    int check()
    {
       int sum,
           x,
           y=0;
    
       for(i=0; i<=9; i++)
          a[i]=a[i]-48;
       for(i=0; i<=9; i++)
       {
          x=y+(i+1)*a[i];
          y=x;
       }
       sum=x%11;
       return sum;
    }
    Inconsistent (or wrong) parts of the app is colored red.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > if(x==a[9])
    x will be an integer 0 to 9
    a[9] will be a char '0' to '9'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Processing a book ISBN
    By richdb in forum C Programming
    Replies: 13
    Last Post: 08-11-2006, 11:14 PM
  2. Calculating next prime number
    By anilemon in forum C Programming
    Replies: 8
    Last Post: 04-17-2006, 10:38 AM
  3. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  4. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 01:10 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM