How to resolve the algorithm Luhn test of credit card numbers step by step in the BBC BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Luhn test of credit card numbers step by step in the BBC BASIC programming language
Table of Contents
Problem Statement
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
For example, if the trial number is 49927398716:
Write a function/method/procedure/subroutine that will validate a number with the Luhn test, and use it to validate the following numbers:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Luhn test of credit card numbers step by step in the BBC BASIC programming language
Source code in the bbc programming language
FOR card% = 1 TO 4
READ cardnumber$
IF FNluhn(cardnumber$) THEN
PRINT "Card number " cardnumber$ " is valid"
ELSE
PRINT "Card number " cardnumber$ " is invalid"
ENDIF
NEXT card%
END
DATA 49927398716, 49927398717, 1234567812345678, 1234567812345670
DEF FNluhn(card$)
LOCAL I%, L%, N%, S%
L% = LEN(card$)
FOR I% = 1 TO L%
N% = VAL(MID$(card$, L%-I%+1, 1))
IF I% AND 1 THEN
S% += N%
ELSE
N% *= 2
S% += N% MOD 10 + N% DIV 10
ENDIF
NEXT
= (S% MOD 10) = 0
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the SETL programming language
You may also check:How to resolve the algorithm Josephus problem step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Monte Carlo methods step by step in the C# programming language
You may also check:How to resolve the algorithm Greyscale bars/Display step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Truth table step by step in the Rust programming language