If you have only valid Roman numbers you could use a simpler algorithms. (i.e IIV is invalid )
The symbols "I", "X", "C", and "M" can be repeated three times in succession, but no more. (They may appear more than three times if
they appear non-sequentially, such as XXXIX.) "V", "L", and "D" can
never be repeated. A common exception to this is the use of IIII on
clocks; see below.
"I" can be subtracted from "V" and "X" only. "X" can be subtracted from "L" and "C" only. "C" can be subtracted from "D" and "M" only.
"V", "L", and "D" can never be subtracted
Only one small-value symbol may be subtracted from any large-value symbol.
Just (string-)replace IV by IIII, IX by VIIII and so on. Afterwards you just have to sum the numbers from left to right.
I didn't try to run it but it seems to me that this algorithm won't handle "Double substractive" forms.
Forms like XIIX instead of XVIII.
How described on wiki – it's not typical roman number usage, but it was used in the past so the program should probably be prepared for it.
main(), nor any definition of
string. Is that supposed to be
#include <string>? Post something that actually compiles. \$\endgroup\$