Luhn test of credit card numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
imported>Thebeez
(Added uBasic/4tH version)
Line 1,495: Line 1,495:
NEXT test
NEXT test
END</syntaxhighlight>
END</syntaxhighlight>

==={{header|uBasic/4tH}}===
{{Trans|C}}
<syntaxhighlight lang="qbasic">Print " 49927398716", Show (Iif(FUNC(_Luhn ("49927398716")), "ok", "fail"))
Print " 49927398717", Show (Iif(FUNC(_Luhn ("49927398717")), "ok", "fail"))
Print "1234567812345678", Show (Iif(FUNC(_Luhn ("1234567812345678")), "ok", "fail"))
Print "1234567812345670", Show (Iif(FUNC(_Luhn ("1234567812345670")), "ok", "fail"))
End

_Luhn
Param (1)
Local (4)

c@ = 1 : d@ = 0

For b@ = Len(a@)-1 To 0 Step -1
e@ = Peek(a@, b@) - Ord("0")
d@ = d@ + Iif (c@, e@, e@+e@-9*(e@>4))
c@ = c@ = 0
Next

Return ((d@ % 10) = 0)
</syntaxhighlight>
{{Out}}
<pre> 49927398716 ok
49927398717 fail
1234567812345678 fail
1234567812345670 ok

0 OK, 0:333</pre>


==={{header|Yabasic}}===
==={{header|Yabasic}}===
Line 1,527: Line 1,557:
fi
fi
next test</syntaxhighlight>
next test</syntaxhighlight>



=={{header|Batch File}}==
=={{header|Batch File}}==