[HELP] ISBN Check Digit (random outputs)

This is a discussion on [HELP] ISBN Check Digit (random outputs) within the C Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> #include <conio.h> #include <stdio.h> #include <string.h> int main() { char cISBN[10]; int i,iLen,iNNF,iISBN[9],iTotal,iCheck; for(;;) /*infinite loop*/ { ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    29

    [HELP] ISBN Check Digit (random outputs)

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
    char cISBN[10];
    int i,iLen,iNNF,iISBN[9],iTotal,iCheck;
    
    for(;;) /*infinite loop*/
    {
    
    for(i=0;i<10;i++)
    {
    cISBN[i]='\0';
    }
    
    printf("ENTER ISBN: ");
    gets(cISBN);
    iLen=strlen(cISBN);
    
    if(iLen!=9)
    {
    printf("ERROR: INCORRECT LENGTH\n\n");
    }
                                    
    else
    {
    iNNF=0;
    iISBN[i]=0;
    iTotal=0;
    iCheck=0;
    
    for(i=0;i<iLen&&iNNF==0;i++)
    {
                                
    if((cISBN[i]<'0')||(cISBN[i]>'9'))
    {
    printf("ERROR: NON-NUMERICAL FOUND\n\n");
    iNNF=1;
    }
                                                                                      
    else
    {
    iISBN[i]=cISBN[i]-48;
    iTotal+=iISBN[i]*(i+1);
    iCheck=iTotal%11;
    }
    
    }
    
    }
                                    
    printf("ISBN CHECK DIGIT: %d\n\n",(iCheck));           
    getch();
                                                                                          
    }
    
    }
    Arithmetic works fine, but it still calculates the check digit and output it, even if I entered an incorrect length ISBN, or an ISBN with non-numericals in it. It should have just tell the user what the error is and ignore the calculations
    Last edited by Dakaa; 04-21-2009 at 09:50 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Initialize total before you start using it. Compile with warnings on and it would alert you to this.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    29
    How, sir? iTotal=0; ?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    That depends if you want it to be zero, or the character for zero.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random Outputs.
    By DarkBrute in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2005, 09:41 PM
  2. outputs number digit by digit
    By Unregistered in forum C++ Programming
    Replies: 14
    Last Post: 05-17-2002, 04:43 PM
  3. modulus check digit
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 02-18-2002, 03:04 PM
  4. ISBN modulus 11 check
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 01-15-2002, 12:03 PM
  5. questions re modulus 10 aka check digit stuff
    By DaWench in forum C++ Programming
    Replies: 2
    Last Post: 11-26-2001, 10:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21