You are here:

C++/convert roman to decimal with recursion


i need help to find out a correct algorith to convert o roman numeral string in a decimal numeral string!

a need only the algorith , don't care about the programming language

i am trying this :

conversion(char *s)
{  if (*s==

a. Create a table of Roman numerals and their values:
     I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, and M = 1000.

b. Initialize sum to the value of the rightmost character in the Roman Numeral string

c. Move left by one character. If there are no more characters to the left, go to finally:
d. Otherwise, compare the value of this Roman numeral with the the one just previous to it.

e. If the current character's value is the same or larger than the previous character, ADD its value to sum.
  Otherwise, if the current character's value is smaller than the previous character, SUBTRACT its value from sum.

f. Repeat steps c to e till the leftmost Roman numeral has been processed. Now sum contains its numeric value.

finally: print out the number sum as a string


All Answers

Answers by Expert:

Ask Experts




my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.


about 15 years or so

post graduate engineer

©2017 All rights reserved.