Roman numerals/Decode: Difference between revisions

Line 2,716:
 
=={{header|FutureBasic}}==
<lang futurebasic>window 1
local fn RomantoDecimal( roman as Str15 ) as short
dim as short i, n, preNum, num
 
local fn RomantoDecimal( roman as Str15CFStringRef ) as shortlong
preNum = 0 : num = 0
dim as shortlong i, n, preNum = 0, num = 0
 
for i = len(roman[0]) to- 1 to 0 step -1
n = 0
if roman[i] = _"M" then n = 10000
select ( fn StringCharacterAtIndex( roman, i ) )
if roman[i] = _"D" then n = 500
if roman[i] = case _"CM" then: n = 1001000
if roman[i] = case _"LD" then: n = 50500
if roman[i] = case _"XC" then: n = 10100
if roman[i] = case _"VL" then: n = 550
if roman[i] = case _"IX" then: n = 1 10
if n < preNumcase then_"V" num = num -: n else num = num + n5
preNum = case _"I" : n = 1
end select
next
if ( n < preNum ) then num = num - n else num = num + n
n preNum = 0n
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" )
 
</lang>
HandleEvents</lang>
 
Output:
416

edits