Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Roman numbers system has the symbols

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

Roman Numbers are formed by combining the above symbols together and adding the values. For example, MMVI is 1000 + 1000 + 5 + 1 = 2006. Generally:
• Symbols are placed in order of value, starting with the largest values.
• When smaller values precede larger values, the smaller values are subtracted from the larger values e.g. IV is 4, IX is 9, and CM is 900.
• When smaller values follow larger values, the smaller values are added to the larger values e.g. VIII is 8, DX is 510, and LXX is 70.
• 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.)
• The symbols V, L, and D can never be repeated.
• Only one small-value symbol may be subtracted from any large-value symbol according to the following:
o I can be subtracted from V and X only.
o X can be subtracted from L and C only.
o C can be subtracted from D and M only.
o V, L, and D can never be subtracted.

Examples:

MCMXLIV 1000 + (1000 − 100) + (50 − 10) + (5 − 1) 1944
MCMLIV 1000 + (1000 – 100) + 50 + (5 – 1) 1954
MCMXC 1000 + (1000 – 100) + (100 – 10) 1990
LXXVIII 50 + 10 + 10 + 5 + 1 + 1 + 1 78
CCCLXIX 100 + 100 + 100 + 50 + 10 + (10 – 1) 369
MMDCCLI 1000 + 1000 + 500 + 100 + 100 + 50 + 1 2751
DCCCXC 500 + 100 + 100 + 100 + (100 – 10) 890

Write a program that prompts the user to enter a string of symbols representing a Roman number. The program converts that roman number to its equivalent decimal number, and then prints both numbers.

If roman is a variable of type string, then roman[0] stores the first character in the string, roman[1] stores the second character in the string, roman[2] stores the third character in the string, and so on.
Posted
Updated 29-Apr-12 4:04am
v2
Comments
phil.o 29-Apr-12 10:06am    
It's your homework. Give it a try if you want people to help you.
DrBones69 29-Apr-12 11:57am    
At first if you don't succeed...
Sergey Chepurin 29-Apr-12 15:39pm    
I strongly suggest you to search for sample code on Internet. This site is to help you to correct errors or to propose a better way to solve a problem. But not to solve it for you. This code you ask about is not new and not interesting for most of us to develop. But you, after finding a sample, can improve it if you want. Like this one: http://www.cplusplus.com/forum/general/27629/

1 solution

Write a program that prompts the user...
No. You write the program.

Here is what is expected of enquirers:
1. TRY first what you want to do!
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900