We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

# Roman numerals

on
Medium Priority
1,109 Views
Assignment: Write a program that accepts a year written as a four digit Arabic (normal) numeral and outputs the year written in Roman numerals. Important Roman numerals are: V for 5, X for 10, L for 50, C for 100, D for 500, and M for 1000.

Comment
Watch Question

## View Solution Only

Commented:
Program Roman;

var year, mag : integer;
var roman     : string;

function get_roman (digit, magnitude : integer) : string;
var one, five, ten : string;
begin
case magnitude of
1:    begin  one := 'I'; five := 'V';   ten := 'X';  end;
10:   begin  one := 'X'; five := 'L';   ten := 'C';  end;
100:  begin  one := 'C'; five := 'D';   ten := 'M';  end;
1000: begin  one := 'M'; five := 'm';   ten := 'n';  end;
end;

case digit of
0: get_roman := '';
1: get_roman := one;
2: get_roman := one + one;
3: get_roman := one + one + one;
4: get_roman := one + five;
5: get_roman := five;
6: get_roman := five + one;
7: get_roman := five + one + one;
8: get_roman := five + one + one + one;
9: get_roman := one + ten;
end;
end;

begin
write ('Enter year: ');

roman := '';
mag   := 1000;
while (mag > 0) do
begin
roman := roman + get_roman (year div mag, mag);
year  := year mod mag;
mag   := mag  div 10;
end;

writeln (roman);
end.

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
Oooo... if you turn in that code, it will be too complex, and your teacher will know you cheated!  Chadd, reject this answer and I will post my simplfied version, so your teacher will not suspect your using other sources!  :)

Commented:
And what makes it so complex? ;-)

Commented:
Oh, I don't know.  I just wanted the points.  :)  It just seems that this source code would come from someone who knew how to do simple Pascal programs, not someone who is struggling through the class, which, I assume, chadd is...  But basically, all I wanted was the points!  :)

Commented:
I thought so. ;-)  I am pretty sure that this code is about the
simplest it can get, considering that the Roman numeral system
is so haphazard in the first place.  Cheers. :-)

Commented:
Thanks.....
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile