Diana V.

asked • 10/04/21

How do i make a for loop for the 11 remaining digits after that (

The final digit of a Universal Product Code is a check digit computed as follows:
Add the digits in the odd-numbered positions from the right (first, third, fifth, etc. - not including the check digit) 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 (ie. the modulo 10 operation). If the remainder is equal to 0 then use 0 as the check digit, and if not 0 subtract the remainder from 10 to derive the check digit.

Algorithm Hints

  1. You can retrieve the last digit using modulo 10.
  2. You can remove the last digit by dividing it by 10.
  3. The check digit is the last digit, you’ll want to save that value first.
  4. There are exactly 11 remaining digits after that (which calls for a for loop).
  5. Even number indexes represent odd-numbered positions.


1 Expert Answer

By:

Robert C. answered • 10/09/21

Tutor
4.8 (6)

Senior iOS/Swift Developer, Lecturer, Computer Science Graduate

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.