Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A delivery company adds a check digit to each parcel number. Each digit is multiplied by a weight, and in turn starting with , and the products are added. The check digit makes the total a multiple of .
Validation checks that data is sensible: range, length, type, presence and format checks, and a check digit. Verification checks that data was entered as intended: a visual check and a double entry check. A validation loop repeats the input, with an error message, until the data is acceptable.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. The weighted sum. .
Step 2. The check digit. The next multiple of is , and . So the check digit is , and the full number is .
Step 3. The swapped digits. For the sum is . The check digit for this would be , not . The computer works out , compares it with the that was typed, and rejects the number.
Answer: (a) the weighted sum is and the check digit is ; (b) the swapped number gives a sum of and a check digit of , which does not match.
Why it works. The and the have different weights, so swapping them changes the sum by .
Log in to join the discussion.
Loading…