modulus check digit

This is a discussion on modulus check digit within the C Programming forums, part of the General Programming Boards category; Having a little difficulty trying to figure out how to apply the check digit here. I need to be able ...

  1. #1
    Unregistered
    Guest

    modulus check digit

    Having a little difficulty trying to figure out how to apply the check digit here. I need to be able to select a product item and check it with the "mod 10 check digit". If it fails then I need it to loop and prompt for the product number again. If zero is entered the the prog shoud terminate.

    This is actually just a chunk of a project I'm working on...everything else makes sense now. Just need to be able to combine this stuff in there......

    #include <stdio.h>

    main()
    {

    int item_number;

    while(item_number)
    {
    printf("\nEnter the item number (zero to quit) > ");
    scanf("%i", &item_number);
    if(item_number==0)
    break;
    else if(item_number<0)

    /*this is where I want to apply mod check*/

    printf("Invalid number, please re-enter.");
    }

    return 0;
    }



    If I can get the check digit in there, it will also prompt for a correct item number if alpha characters are entered, correct?

    Thanks.

  2. #2
    Unregistered
    Guest
    sorry forgot to add this.....
    this is what I'm working off of.


    Technique: mod 10 Check Digit

    Source: Encyclopedia of Computer Science and Engineering, Second Edition. "To generate a check digit using the mod 10 technique, work from right to left. First multiply the digits in the odd positions by 2. if an individual result is greater than 10, add 1 to the units position to obtain a single digit adjusted result. Sum the results along with the even-positioned digits. The number that must be added to make this result evenly divisible by 10 is the check digit." (page 423)

    Example: Consider an item number 835174. The least significant digit (4) is the check digit. To determine if the (actual) item number (83517) is a valid item number do the following: 1. Extract the odd numbered digits from right to left from the actual item number. These would be 7, 5 and 8. 2. Multiply each by 2: 7 X 2 = 14, 5 X 2 = 10 and 8 X 2 = 16. 3. If any of the products from step 2 are greater than 10, add 1 to the units position and discard the remainder of the product e.g. since 7 X 2 = 14 add 1 to 4 (the units position) and discard everything else. 4. Sum the adjusted products plus the digits from the even numbered posit- ions: 5 + (1) + 10 + (3) + 7 = 26 (the digits in parenthesis are the even numbered digits). 5. The next largest number evenly divisible by 10 is 30 and the difference between 26 and 30 is 4 which is the check digit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error msg instead of the result so far
    By maybabier in forum C Programming
    Replies: 25
    Last Post: 03-20-2009, 03:45 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Adding a Large number digit by digit
    By mejv3 in forum C Programming
    Replies: 23
    Last Post: 09-21-2007, 04:00 PM
  4. Adding a Large number digit by digit
    By mejv3 in forum C Programming
    Replies: 1
    Last Post: 09-14-2007, 04:28 AM
  5. Check application visibility
    By 3saul in forum Linux Programming
    Replies: 2
    Last Post: 02-13-2006, 05:13 PM

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