Question
Question 27 (Programming in FORTRAN) Most items sold in stores can be identified by a 12 digit Universal Product Code (UPC). In order to reduce
Question 27 (Programming in FORTRAN)
Most items sold in stores can be identified by a 12 digit Universal Product Code (UPC). In order to reduce scanning errors, the final digit of this code is a check digit. It is computed as follows (the algorithm is taken from http://en.wikipedia.org/wiki/Check_digit)
Add the digits (up to but not including the check digit) in the odd-numbered positions (first, third, fifth, etc.) together and multiply by three.
Add the digits (up to but not including the check digit) in the even-numbered positions (second, fourth, sixth, etc.) to the result.
Take the remainder of the result divided by 10 (modulo operation) and subtract this from 10 to derive the check digit.
For instance, the UPC barcode for a box of tissues is "036000241457". The last digit is the check digit "7", and if the other numbers are correct then the check digit calculation must produce 7.
Add the odd number digits: 0+6+0+2+1+5 = 14
Multiply the result by 3: 14 3 = 42
Add the even number digits: 3+0+0+4+4 = 11
Add the two results together: 42 + 11 = 53
To calculate the check digit, take the remainder of (53 / 10), which is also known as (53 modulo 10), and subtract from 10. Therefore, the check digit value is 7.
Write a Fortran program that reads a 12 digit UPC of the form 036000241457 and determines whether the code is valid or not. It will output a message Valid Code if the check digit is correct and Invalid Code if the check digit is incorrect. Note that the input has no spaces between the digits.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started