Task

Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer.

You don't need to validate the form of the Roman numeral.

Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately,

starting with the leftmost decimal digit and skipping any 0s   (zeroes).

1990 is rendered as   MCMXC     (1000 = M,   900 = CM,   90 = XC)     and

2008 is rendered as   MMVIII       (2000 = MM,   8 = VIII).

The Roman numeral for 1666,   MDCLXVI,   uses each letter in descending order.




  print "MCMXCIX = "; romanDec( "MCMXCIX") '1999
  print "MDCLXVI = "; romanDec( "MDCLXVI") '1666
  print "XXV     = "; romanDec( "XXV")     '25
  print "CMLIV   = "; romanDec( "CMLIV")   '954
  print "MMXI    = "; romanDec( "MMXI")    '2011
 
  end
 
function romanDec( roman$)
  arabic  =0
  lastval =0
 
  for i = len( roman$) to 1 step -1
    select case upper$( mid$( roman$, i, 1))
      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
      case else
        n = 0
    end select
 
    if n <lastval then
      arabic =arabic -n
    else
      arabic =arabic +n
    end if
 
    lastval =n
  next
 
  romanDec =arabic
end function