Big assignment problem that you're all going to do for me!
Re: Your following query
Subject: Big assignment problem that you're all going to do for me!
From: "Mikhovitch (Caglios)"
Date: Tue, 9 Sep 1997 12:29:07 +1000
I am to write a roman calculator thingie and the answer is to be
If your input AND output are in Roman numeral form, as I am sure you
already know, you need procedures to convert a string (or array of
chars) of Roman numeral form to a decimal integer and vice versa.
A little history to help your thought process. Roman numbers come from
the way their "computers" worked. The Roman way of calculating was
like the Abacus, i.e. a biquinary system using fives and ones. They
originally drew lines in the dirt and used stones as markers. When
merchants moved inside, they painted lines on the table and that is
the origin for the English word, "counter" as in, "Take it to the
CONVERTING A DECIMAL INTEGER TO A ROMAN NUMERAL SYMBOL STRING
Assume you have the decimal number 4597. To find the right most Roman
numeral you perform-- 4597 mod 10 = 7. There are several ways to
convert 7 to VII. However, since 5, 50 and 500 all use a different
symbol (because there is no 0 symbol) you might consider:
7 div 5 := 1, for one "V"
7 mod 5 := 2. for two "I"s
To extract the "9", first do 4597 div 10 = 459 then:
459 mod 10 = 9
Although the ancient Romans did use IIII and VIIII to represent 4 and
9, this changed to the thought used in Abacus subtraction and addition
with a carry. Four is five take away one, represented as IV with 9 as
You have to keep up with the bookkeeping. This 9 really represents 90,
so the symbol is 100 - 10 or XC.
So far we have the last Roman symbols, "XCVII", with the 4500 still to
A CASE statement is recommended for 1..3, 4, 5..8 and 9 in conjunction
with the place values, 1, 10, 100...etc to choose your symbols.
CONVERTING AN INPUT ROMAN STRING TO A DECIMAL INTEGER
I would parse the string (or char array) from the right. As long as
the next symbol is equal or greater, keep adding 1, 10, 100... or 5,
50, 500... Any time the next symbol value is less than the previous
right symbol value, subtract this lower value from the total value.