' iBcNumerus.ibas
{CREATORID "LDIN"}
{VERSION "1.2"}

_Convert1Num:
   A=P MOD 10
   IF A=1 LET N$="I"+N$
   IF A=2 LET N$="II"+N$
   IF A=3 LET N$="III"+N$
   IF A=4 LET N$="IV"+N$
   IF A=5 LET N$="V"+N$
   IF A=6 LET N$="VI"+N$
   IF A=7 LET N$="VII"+N$
   IF A=8 LET N$="VIII"+N$
   IF A=9 LET N$="IX"+N$
   B=P MOD 100 -A
   IF B=10 LET N$="X"+N$
   IF B=20 LET N$="XX"+N$
   IF B=30 LET N$="XXX"+N$
   IF B=40 LET N$="XL"+N$
   IF B=50 LET N$="L"+N$
   IF B=60 LET N$="LX"+N$
   IF B=70 LET N$="LXX"+N$
   IF B=80 LET N$="LXXX"+N$
   IF B=90 LET N$="XC"+N$
   C=P MOD 1000 -B -A
   IF C=100 LET N$="C"+N$
   IF C=200 LET N$="CC"+N$
   IF C=300 LET N$="CCC"+N$
   IF C=400 LET N$="CD"+N$
   IF C=500 LET N$="D"+N$
   IF C=600 LET N$="DC"+N$
   IF C=700 LET N$="DCC"+N$
   IF C=800 LET N$="DCCC"+N$
   IF C=900 LET N$="CM"+N$
   D=P MOD 10000 -C -B -A
   IF D=1000 LET N$="M"+N$
   IF D=2000 LET N$="MM"+N$
   IF D=3000 LET N$="MMM"+N$
   IF D=4000 LET N$="MMMM"+N$
RETURN

_Convert2Nums:
   P=N MOD 1000
   GOSUB _Convert1Num
   N$=".M "+N$
   P=N\1000
   GOSUB _Convert1Num
RETURN

_ConvertToRoman:
   PRINT "In Roman numerals, ";
   PRINT N USING 0;
   PRINT " is:"
   N$=""
   IF N<=4999 THEN
      P=N : GOSUB _Convert1Num
   ELSE GOSUB _Convert2Nums
   ENDIF
   PRINT N$
RETURN

BEGIN
CLS
A$=SPACE$(10) : PRINT A$;
PRINT "Numerus"
PRINT
PRINT "Convert Arab Numerals [0..9]"
PRINT "to Roman Numerals [IVXLCDM]."
REPEAT
   Q=0
   REPEAT
      PRINT "Input an integer number" : PRINT "(0 to exit):"
      INPUT N
      M=INT(N)
      IF N=M LET Q=1
      IF N<0 LET Q=0
   UNTIL Q=1
   IF N>0 GOSUB _ConvertToRoman
UNTIL N=0
END