how do you write a program that converts a number entered in Roman numerals to decimal?

The dicimal values of the roman numerals are

M 1000
D 500
C 100
L 50
X 10
V 5
I 1

Recommended Answers

All 2 Replies

First, We don't code for you... we can only help provided you give your code that you need help with

Second, if just your just asking for suggestions then you can use arrays and an if statement to compare the letters to their corresponding number..then do the operations required to match the whole roman numeral counterpart...but that's where it gets complicated

Member Avatar for hfx642

A string for your input.
A string to hold the letters "MDCLXVI".
An array to hold your amounts to correspond to the letters.
Loop through your input string to process the letters one character at a time.
Find the postition of the character in your letters.
Use that as your index of your array.
Total everything up.
Carefull!!! Watch for your 4s (IV), 9s (IX), 40s (XL), 90x (XC), etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.