Hi Guys,
Pls I need to know how a program can accept a roman numeral as string and then display it's decimal equivalent. Thanks for your estimeed assistance.
Printable View
Hi Guys,
Pls I need to know how a program can accept a roman numeral as string and then display it's decimal equivalent. Thanks for your estimeed assistance.
Presumably you know how roman numerals work? You'll need to step through a string character by character, keeping track of the sum you have reached. If you get to a character of higher value than the previous, then you do a subtraction. You probably need to keep track of 3 numbers to deal with stuff like MIIC. You also need to decide whether you're going to try and handle non-standard forms (XCIIX vs. IIC) or just throw a malformed exception.
I would step through the String backwards, starting at the last character.
And MIIC, XCIIX and IIC are *all* illegal as roman numerals. 98 can be written one way and one way only: XCVIII. 1098 would be MXCVIII
db
Oh yeah, silly me