RosettaCodeData/Task/SEDOLs/BASIC/sedols.basic

32 lines
892 B
Plaintext

DECLARE FUNCTION getSedolCheckDigit! (str AS STRING)
DO
INPUT a$
PRINT a$ + STR$(getSedolCheckDigit(a$))
LOOP WHILE a$ <> ""
FUNCTION getSedolCheckDigit (str AS STRING)
IF LEN(str) <> 6 THEN
PRINT "Six chars only please"
EXIT FUNCTION
END IF
str = UCASE$(str)
DIM mult(6) AS INTEGER
mult(1) = 1: mult(2) = 3: mult(3) = 1
mult(4) = 7: mult(5) = 3: mult(6) = 9
total = 0
FOR i = 1 TO 6
s$ = MID$(str, i, 1)
IF s$ = "A" OR s$ = "E" OR s$ = "I" OR s$ = "O" OR s$ = "U" THEN
PRINT "No vowels"
EXIT FUNCTION
END IF
IF ASC(s$) >= 48 AND ASC(s$) <= 57 THEN
total = total + VAL(s$) * mult(i)
ELSE
total = total + (ASC(s$) - 55) * mult(i)
END IF
NEXT i
getSedolCheckDigit = (10 - (total MOD 10)) MOD 10
END FUNCTION