Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting from roman numerals to standard numbers

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello.

For my C++ programming class, I need to be able to write a program that will read Roman numerals. Like if 'XXII' is input, the program will read that as 22. Any ideas? Thanks
 
12rs,

We do not solve homework problems in this forum. That being said, the best approach is probably to do some conversons by hand. Then force your program to step through the same decision process, but for the general case.

Brudnakm
 
Isn't this as simple as parsing a table, then adding all the numbers?? If someone enters MMDXI you would add 1000, 1000, 500, 10 and 1, for 2511?? Maybe it's more complicated than that, but hey, it's your class!!

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

Tim
 
The big problem hear is we dont know how much you know about C. It's not really a hard problem. Just read the roman numeral into an array, (or a dynamically allocated string if you know how) and just move through it one piece at a time and add or subtract as appropriate.

You could use a big switch statement to do all the work, or you could come up with a hash. There's really a lot of ways to do it.

Tell me, do you have to convert just a few particular ones or do you have to interact with an end user, or are you reading from a file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top