Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
program CreditCardValidator; // COPY INTO LAZARUS TO RUN
uses sysutils;
var
cardNum: string;
total, digit, currentDigit: integer;
begin
while true do
begin
writeln('Enter a 16-digit credit card number: ');
readln(cardNum);
total := 0;
for digit := 1 to 15 do
begin
if digit mod 2 = 1 then
begin
currentDigit := strtoint(cardnum[digit]) * 2;
while length(inttostr(currentDigit)) <> 1 do
currentDigit := strtoint(inttostr(currentDigit)[1]) + strtoint(inttostr(currentDigit)[2]);
total += currentDigit;
end
else
total += strtoint(cardNum[digit]);
end;
if strtoint(cardNum[16]) = 10 - (total mod 10) then
writeln('Credit card valid!')
else
writeln('Invalid credit card!');
end;
end.
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more