Solved

Roman numerals

Posted on 1997-11-09
6
1,031 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
Comment Utility
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
Comment Utility
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
Comment Utility
And what makes it so complex? ;-)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 2

Expert Comment

by:mitchell042997
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.....
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

11 Experts available now in Live!

Get 1:1 Help Now