Arabic to Roman Numerals?

Hi,
I need to write a program to convert arabic numbers to roman numbers, but we are allowed to use neither strings, nor arrays. we aren't supposed to call modular functions either. I'm having trouble thinking about the algorithm for this. any advice? thank you!
Can you use array of char?
without using strings or arrays, then how does the instructor expect to store "MDMLXXVIII" ??

if it WERE in a string or array then something like this could be parsed , one char at a time, and with some RULES could produce 1978

if char = "M" then ans = 1000
if next char = "D" then hold-on and look ahead
if next (3rd) char ' "M" then calc the "D" and the "M" together
and add 900 to the ans. (ans now = 1900

if the next char (4th ) is a "L" then add 50 to ans.
1950

if the next char is a "X" then add 10 to ans
1960
...

Watch out for the "MD" or "XL" or "XC" special numbers.

Without Strings or arrays- ...

You can do it in memory Take the first char into memory and add it to another char in memory and store the ans in memory.

and the addition and calculations can all be accomplished by taking the ASCII value of each char.

077, 068, 077, 076, 088, 088, 086, 043, 043, 043

M..... D..... M ..... L ..... X ..... X..... V ..... I ..... I ..... I



Last edited on
can you use vectors? otherwise a while statement like while(char != '\n'){stuff} might work, it will do until the user hits enter(new line char). i am just guessing, never tried without any kind of data aggregate.
he wants us to write 4 pages of code.
no arrays, no strings, no vectors.

i've started a switch,

and as for the example above, thanks, but its actually a conversion the other way around.
Topic archived. No new replies allowed.