Solved

Roman numerals

Posted on 1997-11-09
6
1,042 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Text alignment in Delphi XE3 TStringGrid when style is gdsThemed. 5 2,003
Delphi Skype API 2 1,857
Lazarus (freePascal) DB Project Assistance 14 490
Conversion ? 15 93
This article was initially published on Monitis Blog, you can read it here . When it comes to deciding which approach to website performance monitoring is best for your business, unfortunately, like so many options in life . . . it depends. In t…
This article was originally published on Monitis Blog, you can check it  here .   Some years back, I worked as the CTO.  During my tenure, I had a head of IT support reporting to me.  He did his job quite well and had a commendable sense of duty…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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