Thread: Help with program

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    5

    Help with program

    The problem is as follows:
    A barcode scanner for Universal Product Codes (UPCs) verifies the 12-digit code scannedby comparing the code’s last digit (called a check digit) to its own computation of the checkdigit from the first 11 digits as follows:
    1. Calculate the sum of the digits in the odd-numbered positions (the first, third, .. ,eleventh digits) and multiply this sum by 3.
    2. Calculate the sum of the digits in the even-numbered positions (the second, fourth, .., tenth digits) and add this to the previous result.
    3. If the last digit of the result from step 2 is 0, then 0 is the check digit. Otherwise,subtract the last digit from 10 to calculate the check digit.
    4. If the check digit matches the final digit of the 12-digit UPC, the UPC is assumedcorrect.

    My issue is when the program is ran, it skips the first if statement ad just prints ERROR IN BARCODE;
    Attached Files Attached Files
    • File Type: c main.c (983 Bytes, 174 views)

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Please post your code here in Code tags.

    Code:
    int bar_code[SIZE], i = 12;
    you are initializing i to 12, but NOT bar_code! This is what you are declaring:
    Code:
    int bar_code[SIZE];  // Uninitialized data!
    int i = 12;
    Start correcting this and test again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 03-15-2016, 06:35 AM
  2. Replies: 2
    Last Post: 09-09-2014, 02:36 PM
  3. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  4. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  5. Replies: 18
    Last Post: 11-13-2006, 01:11 PM

Tags for this Thread