Task

Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero.



In Roman numerals:

 1990 is rendered: 1000=M, 900=CM, 90=XC; resulting in MCMXC
 2008 is written as 2000=MM, 8=VIII; or MMVIII
 1666 uses each Roman symbol in descending order: MDCLXVI


window 1
 
local fn DecimaltoRoman( decimal as short ) as Str15
  short arabic(12)
  Str15 roman(12)
  long  i
  Str15 result : result = ""
 
  arabic(0) = 1000 : arabic(1) = 900 : arabic(2) = 500 : arabic(3) = 400
  arabic(4) = 100  : arabic(5) = 90  : arabic(6) = 50  : arabic(7)  = 40
  arabic(8) = 10   : arabic(9) = 9   : arabic(10) = 5  : arabic(11) = 4: arabic(12) = 1
 
  roman(0) = "M" : roman(1) = "CM" : roman(2) = "D"  : roman(3)  = "CD"
  roman(4) = "C" : roman(5) = "XC" : roman(6) = "L"  : roman(7)  = "XL"
  roman(8) = "X" : roman(9) = "IX" : roman(10) = "V" : roman(11) = "IV" : roman(12) = "I"
 
  for i = 0 to 12
    while ( decimal >= arabic(i) )
      result = result + roman(i)
      decimal = decimal - arabic(i)
    wend
  next i
  if result == "" then result = "Zepherium"
end fn = result
 
print "1990 = "; fn DecimaltoRoman( 1990 )
print "2008 = "; fn DecimaltoRoman( 2008 )
print "2016 = "; fn DecimaltoRoman( 2016 )
print "1666 = "; fn DecimaltoRoman( 1666 )
print "3888 = "; fn DecimaltoRoman( 3888 )
print "1914 = "; fn DecimaltoRoman( 1914 )
print "1000 = "; fn DecimaltoRoman( 1000 )
print " 513 = "; fn DecimaltoRoman(  513 )
print "  33 = "; fn DecimaltoRoman(   33 )
 
HandleEvents