Solved

Roman numerals

Posted on 1997-11-09
6
1,037 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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