Imports System
Public Module Module1
Public Sub Main()
' This program reads in the first 12 digits of an ISBN-13 number into an array
' It then calculates the 13th digit (Check Digit) using the following algorithm:
' a. Multiply the digits in the odd positions by 1 and in the even positions by 3
' and add all of these numbers to form a grand total.
' b. Then find the remainder when this total is divided by 10 (what function do you need?)
' c. Then subtract the remainder from 10.
' d. Finally, if this number is 10, then the Check Digit becomes 0, otherwise leave it alone
' Program Template
' ----------------
' Think about the variables you will need and suggest suitable names, eg ISBN13(13), CheckDigit, Total, etc....
' Now write the Dim statement:
Dim ISBN13(13), CheckDigit, Total As Integer
' You now need to ask the user to enter each of the first 12 digits into each of the array elements
For i = 1 to 12
Console.WriteLine("Enter digit " & i)
ISBN13(i) = Console.ReadLine()
Next i
' You now need to loop through the array to calculate the total as per algorithm above
' Firstly, initialise the total
Total = 0
' If it's an odd number position then multiply the ISBN13 digit by 1 otherwise multiply it by 3 and add it to the total
' How can you check for ODD/EVEN numbers - think about a certain mathematical function!!
If i MOD 2 = 0 Then
Total = Total + ISBN13(i) * 1
Else
Total = Total + ISBN13(i) * 3
End If
' Now you can start calculating the Check Digit itself
' Subtract the remainder of total when divided by 10 from the number 10
CheckDigit = 10 - Total MOD 10
' If the check digit is 10 then it becomes 0
If CheckDigit = 10 Then
CheckDigit = 0
' Now populate the 13th element of the ISBN13 array with the check digit
ISBN13(13) = CheckDigit
' Finally print out all 13 digits of the ISBN13 number including the check digit
For i = 1 to 13
Console.WriteLine(ISBN13(i))
End Sub
End Module
' PSEUDOCODE
' ----------
' INTEGER: ISBN[13], CheckDigit, Total
' FOR i <-- 1 TO 12
' OUTPUT "Enter digit ", i
' INPUT ISBN13[i]
' NEXT i
' Total <-- 0
' IF i MOD 2 = 0 THEN
' Total <-- Total + ISBN13[i] * 1
' ELSE
' Total <-- Total + ISBN13[i] * 3
' ENDIF
' CheckDigit = 10 - Total MOD 10
' IF CheckDigit = 10 THEN
' CheckDigit <-- 0
' ISBN13[13] <-- CheckDigit
' FOR i <-- 1 TO 13
' OUTPUT ISBN13[i]