13 digit product codes: Check if total is a multiple of 10 (entered one at a time)

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Write a program that asks the user to enter a 13 digit product code, entering each digit one at a time. Then adds up all the digits, every second one multiplied by 3 (2nd, 4th, and so on) and show if this total is a multiple of 10 or not.

Testing examples:

Your program should display the outputs shown in this table for the given inputs provided:

Example

Input

Enter digit 1 of the product code:
9

Enter digit 2 of the product code:
4

Enter digit 3 of the product code:
2

Enter digit 4 of the product code:
1

Enter digit 5 of the product code:
9

Enter digit 6 of the product code:
0

Enter digit 7 of the product code:
2

Enter digit 8 of the product code:
8

Enter digit 9 of the product code:
1

Enter digit 10 of the product code:
4

Enter digit 11 of the product code:
7

Enter digit 12 of the product code:
9

Enter digit 13 of the product code:
2

Output

The sum is a multiple of 10

Languages

Scratch

What it should look like

Click on the green flag, enter the inputs provided in the “testing examples” to see the expected output of your program.

Recommended blocks
when green flag clicked
say [The sum is NOT a multiple of 10]

say [The sum is a multiple of 10]
ask (join (join [Enter digit ] (index)) [ of the product code:]) and wait

ask (join (join [Enter digit ] (index)) [ of the product code:]) and wait

ask (join (join [Enter digit ] (index)) [ of the product code:]) and wait
repeat (6)
end

if <((total) mod (10)) = [0]> then
else
end
set [odd total v] to [0]

set [even total v] to [0]

set [index v] to [1]

change [odd total v] by (answer)

set [total v] to ((odd total) + ((even total) * (3)))

change [index v] by (1)

change [odd total v] by (answer)

change [index v] by (1)

change [even total v] by (answer)
Hints
  • You need to add up 1st, 3rd, 5th and so on digits and store the result in a variable called "total 1". Then add up 2nd, 4th, 6th and so on digits and store the result in a variable called "total 2". Store the sum of "total 2" multiplied by 3 and "total 1" in a variable called "total". The output displays if this total is a multiple of 10 or not (i.e. if “total” mod 10 is equal to 0).

Show Scratch solution