home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
pascal
/
library
/
dos
/
chkdigit
/
chkdgt.pas
Wrap
Pascal/Delphi Source File
|
1986-04-02
|
3KB
|
77 lines
program chkdgt; (* Computes MOD 9 Check Digit - Example *)
(* Program - CHKDGT.PAS
This is an example routine that demonstrates how a simple CHECK DIGIT
routine can be done. In this example, a charge account number of fifteen
digits with a sixteenth digit being the check digit is used. To put it
simply, the sum of the first fifteen digits when divided by the check
digit value should give a remainder that is equal to the sixteenth digit
in value.
In this example I have used a check digit of 9.
SAMPLE 15 DIGIT NUMBER - 123456789012345 SIXTEENTH DIGIT 6
This number if entered as input should print out as an answer
the check digit value 6 which is equal to the sixteenth digit
in value so the charge number probably valid.
ENJOY,
Bob Palla
*)
var
charge_num : string[20];
nxt_digit : integer;
sum_of_digits : integer;
place_of_digit : integer;
result : integer;
check_digit : integer;
begin
sum_of_digits:=0; (* zero counters *)
clrscr; (* prepare screen *)
gotoxy(10,10);
write(' Input a 15 digit number. '); (* prompt for charge number *)
readln(charge_num); (* get it *)
for place_of_digit:=1 to 15 do (* loop to compute sum of *)
(* digits *)
begin
val (copy(charge_num, place_of_digit, 1), nxt_digit, result);
sum_of_digits := sum_of_digits + nxt_digit;
end;
check_digit := sum_of_digits mod 9; (* compute CHECK DIGIT *)
(* Modulo 9 *)
writeln('Check Digit (Modulo 9) = ',check_digit:4);
readln; (* wait for user to press *)
(* a key - then go on *)
end. (* end of chkdgt.pas routine *)counters *)
clrscr; (* prepare screen *)
gotoxy(10,10);
write(' Input a 15 digit number. '); (* prompt for charge number *)
readln(charge_num); (* get it *)
for place_of_digit:=1 to 15 do (* loop to compute sum of *)
(* digits *)
begin
val (copy(charge_num, place_of_digit, 1), nxt_digit, result);
sum_of_digits := sum_of_digits + nxt_digit;
end;
check_digit := sum_of_digits mod 9; (* compute CHECK DIGIT *)
(* Modulo 9 *)
writeln('Check Digit (Mod