Roman numerals/Decode: Difference between revisions
Content added Content deleted
Line 2,716: | Line 2,716: | ||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
<lang futurebasic> |
<lang futurebasic>window 1 |
||
⚫ | |||
⚫ | |||
⚫ | |||
preNum = 0 : num = 0 |
|||
⚫ | |||
for i = roman |
for i = len(roman) - 1 to 0 step -1 |
||
⚫ | |||
n = 0 |
|||
select ( fn StringCharacterAtIndex( roman, i ) ) |
|||
if roman[i] = _"D" then n = 500 |
|||
case _"M" : n = 1000 |
|||
case _"D" : n = 500 |
|||
case _"C" : n = 100 |
|||
case _"L" : n = 50 |
|||
case _"X" : n = 10 |
|||
case _"V" : n = 5 |
|||
case _"I" : n = 1 |
|||
end select |
|||
⚫ | |||
if ( n < preNum ) then num = num - n else num = num + n |
|||
⚫ | |||
⚫ | |||
end fn = num |
end fn = num |
||
print " MCMXC ="; fn RomantoDecimal( "MCMXC" ) |
print @" MCMXC = "; fn RomantoDecimal( @"MCMXC" ) |
||
print " MMVIII ="; fn RomantoDecimal( "MMVIII" ) |
print @" MMVIII = "; fn RomantoDecimal( @"MMVIII" ) |
||
print " MMXVI ="; fn RomantoDecimal( "MMXVI" ) |
print @" MMXVI = "; fn RomantoDecimal( @"MMXVI" ) |
||
print "MDCLXVI ="; fn RomantoDecimal( "MDCLXVI" ) |
print @"MDCLXVI = "; fn RomantoDecimal( @"MDCLXVI" ) |
||
print " MCMXIV ="; fn RomantoDecimal( "MCMXIV" ) |
print @" MCMXIV = "; fn RomantoDecimal( @"MCMXIV" ) |
||
print " DXIII ="; fn RomantoDecimal( "DXIII" ) |
print @" DXIII = "; fn RomantoDecimal( @"DXIII" ) |
||
print " M ="; fn RomantoDecimal( "M" ) |
print @" M = "; fn RomantoDecimal( @"M" ) |
||
print " DXIII ="; fn RomantoDecimal( "DXIII" ) |
print @" DXIII = "; fn RomantoDecimal( @"DXIII" ) |
||
print " XXXIII ="; fn RomantoDecimal( "XXXIII" ) |
print @" XXXIII = "; fn RomantoDecimal( @"XXXIII" ) |
||
</lang> |
|||
HandleEvents</lang> |
|||
Output: |
Output: |