Back to Challenge Set 17

Code Challenge: Roman Numerals

Extra CreditOptional. Not required for any homework drop.

Difficulty  

divider

The Brief

What they asked for
Turn a number into Roman numerals. Up to 3999 is enough.
I want it as a method I can call from other programs,
and it prints the numeral.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Work out the algorithm on paper before writing anything. This one punishes coding first.
  • The subtractive cases — IV, IX, XL, XC, CD, CM — are where every attempt breaks.
  • Test 4, 9, 14, 40, 90, 400, 1990, and 3999. If all eight work, it works.
  • There is a way to do this with two arrays and a loop that is far shorter than a wall of ifs.
  • Print the numeral one piece at a time with Console.Write. Building text with + is not something this course has taught yet.

Sample Output

Sample Output
1990 -> MCMXC
2024 -> MMXXIV
4 -> IV

1990 is M, then CM, then XC: one thousand, nine hundred, ninety.


Submit

Your requirements list and your program file, named cc-roman-numerals.

Commence Challenge