This program is a part of an exam I just took, that I had to write. I only got this far and couldn't get anywhere.
Here is the problem description:
Write a Test Function toDecimal() that converts a Roman numeral, such as MMLXVII, to it's decimal number representation. Use main() to test the function.
The toDecimal() function should have 2 arguments, the string array of Roman numerals and a helper function. This helper function will return the numeric value of each of the letters used in Roman numerals.
Then, convert the string arguments as so: Look at the first two characters, if the first is larger, convert the first, and add it to the summation, then call the conversion function again with the second value, and add both. IF the first character is less than the second, subtract the first from the second, and add the result to the conversion of the string. Without validation this will also convert strings like "IC".
Validate the string argument, and, if there is an error, call the error processing function.
Provide at least two error processing functions, and test toDecimal() with each. One could be asking the user to correct; the other may correct it.
- I, X, C, and M cannot be repeated more than 3 times in succession.
- D, L, and V can never be repeated in succession.
- I can only be subtracted from V and X.
- X can only be subtracted from L and C.
- C can only be subtracted from D and M.
- V, L, and D can never be subtracted.
I've lost about 2 days worth of sleep on this, tried writing it hundreds of different ways using and breaking the rules. This is the closest I've gotten on it.
#include
#include
#include
** I have added the help of people on here. This is an edit to show an progress/congress.