RosettaCodeData/Task/Roman-numerals-Decode/FutureBasic/roman-numerals-decode.futur...

29 lines
922 B
Plaintext

local fn RomantoDecimal( roman as Str15 ) as short
dim as short i, n, preNum, num
preNum = 0 : num = 0
for i = roman[0] to 1 step -1
n = 0
if roman[i] = _"M" then n = 1000
if roman[i] = _"D" then n = 500
if roman[i] = _"C" then n = 100
if roman[i] = _"L" then n = 50
if roman[i] = _"X" then n = 10
if roman[i] = _"V" then n = 5
if roman[i] = _"I" then n = 1
if n < preNum then num = num - n else num = num + n
preNum = n
next
end fn = num
print " MCMXC ="; fn RomantoDecimal( "MCMXC" )
print " MMVIII ="; fn RomantoDecimal( "MMVIII" )
print " MMXVI ="; fn RomantoDecimal( "MMXVI" )
print "MDCLXVI ="; fn RomantoDecimal( "MDCLXVI" )
print " MCMXIV ="; fn RomantoDecimal( "MCMXIV" )
print " DXIII ="; fn RomantoDecimal( "DXIII" )
print " M ="; fn RomantoDecimal( "M" )
print " DXIII ="; fn RomantoDecimal( "DXIII" )
print " XXXIII ="; fn RomantoDecimal( "XXXIII" )