Rem   Roman.bas - Program to decode a Roman Numeral String
DIM R$(7), A(7)
Rem  Valid Chars. in a Roman Numeral and their Values
R$(1) = "I"  : A(1) = 1
R$(2) = "V"  : A(2) = 5
R$(3) = "X"  : A(3) = 10
R$(4) = "L"  : A(4) = 50
R$(5) = "C"  : A(5) = 100
R$(6) = "D"  : A(6) = 500
R$(7) = "M"  : A(7) = 1000
PRINT "ROMAN NUMERAL DECODER"
PRINT "*********************"
INPUT "Enter the Roman Numeral:", T$
L = LEN(T$)  : VALUE = 0
IF L = 1 THEN X$ = T$ : GOSUB 1000 : VALUE = V : GOTO 40
FOR I = 1 TO L-1
   CURCHAR$ = MID$(T$,I,1)
   NXTCHAR$ = MID$(T$,I+1,1)
   X$ = CURCHAR$ : GOSUB 1000 : CURVAL = V
   X$ = NXTCHAR$ : GOSUB 1000 : NXTVAL = V
'  IF THE NEXT CHAR IS GREATER, SUBTRACT THE VALUE OF CURRENT CHAR.
   IF NXTVAL > CURVAL THEN VALUE = VALUE - CURVAL : GOTO 20
' OTHERWISE ADD THE VALUE OF CURRENT CHAR.
   VALUE = VALUE + CURVAL
20 NEXT
' NOW ADD VALUE OF THE LAST CHAR.
VALUE = VALUE + NXTVAL
40 PRINT USING "Equivalent Decimal Number =#######"; VALUE
END

REM SUBROUTINE TO FIND VALUE(V) OF THE CHAR(X$)
1000 FOR J = 1 TO 7
       IF UCASE$(X$) = R$(J) THEN V = A(J) : RETURN
NEXT

REM CONTROL WILL REACH HERE IF X$ IS INVALID.PRINT ERROR MESSAGE & DIE.
PRINT USING "Invalid Char '&' found"; X$
END
