Question: Problem 2 (20 points): A barcode scanner verifies the 12-digit code scanned by comparing the code's last digit to its own computation of the check
Problem 2 (20 points): A barcode scanner verifies the 12-digit code scanned by comparing the code's last digit to its own computation of the check digit calculated from the first 11 digits as follows: 1. Calculate the sum of the digits in the odd-numbered indices (the first, third, ..., ninth digits) and multiply this sum by 3. 2. Calculate the sum of the digits in the even-numbered indices (the 0th, second,... tentlh digits) 3. Add the results from step 1 and 2. If the last digit of the addition result is 0, then 0 is the check digit Otherwise, subtract the last digit of the result from 10 to calculate the check digit 4. If the check digit matches the last digit of the barcode, the barcode is valid. Write an interactive C program that prompts the user to enter the 12 digits of a barcode separated by spaces. The program should store the digits in an integer array (-10 points if the array is NOT used in your program), calculate the check digit, and compare it to the last digit of the barcode. If the digits match, output with the message "barcode is validated." If not, output with the message "error in barcode." See sample code execution below: Note: loop structure should be used to access the array in step 1 and 2 above. Sample code execution (Red entered by a user) Enter 12-digit barcode (separate each digit by space) For the barcode 0 7 9400804501 sum of od -7+4++0+5 16 sum of even 0+9+0+8 +4+0 sum from first 11 digits 16*3+21 69 079400804501 sum of digits in the odd-numbered indices 16 sum of digits in the even-numbered indices 21 sum from the first 11 digits 69 barcode is valid Continue (q/Q to quit): y Enter 12-digit barcode (separate each digit by space) 0 11110856807 sum of digits in the odd-numbered indices 15 sum of digits in the even-numbered indices 16 21 Since the last digit of 69 is 9 (not 0), check digit 10-91 Since 1 (from the line above) the last digit of the barcode valid barcode sum from the first 11 digits 61 error in barcode Continue (q/Q to quit): y Enter 12-digit barcode (separate each digit by space) 011110856827 sum of digits in the odd-numbered indices 15 sum of digits in the even-numbered indices 18 sum from the first 11 digits 63 barcode is valid Continue (q/Q to quit): Enter 12-digit barcode (separate each digit by space 024000162869 sum of digits in the odd-numbered indices 16 sum of digits in the even-numbered indices 13 sum from the first 11 digits 61 barcode is valid Continue (q/Q to quit)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
