Solved

Roman numerals

Posted on 1997-11-09
6
1,035 Views
Last Modified: 2006-11-17
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.

Please provide the code. Thanks!
0
Comment
Question by:chadd082197
  • 3
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
delphinus earned 200 total points
ID: 1216623
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: ');
    readln (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.

0
 
LVL 2

Expert Comment

by:mitchell042997
ID: 1216624
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!  :)
0
 
LVL 1

Expert Comment

by:delphinus
ID: 1216625
And what makes it so complex? ;-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:mitchell042997
ID: 1216626
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!  :)
0
 
LVL 1

Expert Comment

by:delphinus
ID: 1216627
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. :-)

0
 

Author Comment

by:chadd082197
ID: 1216628
Thanks.....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now