Roman Numeral Converter

I would like to make a simple program for absoluteley no use what-so-ever, expect for my own amusement
that would ask the user to enter string.  If user inputs "25" the output would be XXV, if the user inputed XXV, the
output would be 25.  I dont want a menu, I want it to automatically to check for which way to convert.  Thanks.

I think this is simple, but don't know how exactly to do it.  thanks/..
weinrjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kellyjjCommented:
Are you looking for psuedo code? or an actual program??  
0
weinrjAuthor Commented:
actual program.
0
tecbuilderCommented:
If you are wanting someone to write the code for you, you need to up the points quite a bit.  It still takes some one time to do the work.  My suggestion is to offer around 150 points.  For 25 points all you'll get is how you need to go about doing it.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

jlove1Commented:
Are you asking for the COMPLETE source code to such a program, or just a description on how to accomplish the task (with code fragments)? If you're wanting Complete source, you will have to add some more points to this.. try starting at 200... I'll do it myself for 400. but you may find someone desprate for points that'll do it for 200.
0
tecbuilderCommented:
jlove1,  400 points?!  For the code for this question?  I can see you really want to move up on the top 15 list fast.  It seems to me that you are the one desperate, for points.  The code for this quesiton is not difficult at all and doesn't warrant anything more than 200.  Calling anyone who answers the question desperate I believe is a bit extreme.  I have not seen too many experts here that are desperate to answer questions.
0
weinrjAuthor Commented:
ok
0
tecbuilderCommented:
If you will post your email address I will send you the program.
0
weinrjAuthor Commented:
I will give you the points, the letter grade, etc., once i get the program via email.  
If it is acceptable, I will grade it, and raise you 200 pts.  Once you email it, post a new message as an answer stating you sent it.  based on that, i will then be able to post the points.

please send email to me at jwnrb@cybernex.net
0
tecbuilderCommented:
I have just sent you the executable.  After you grade my answer I will send you the source code if you want it.  This was one of the those programs that was just fun to do.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
Do you handle such input as
VIIIII
or
IC
?

0
tecbuilderCommented:
Yes, the program will evaluate IC as 99 and VIIIII as 10.  If the program is accepted I will post the code here.
0
weinrjAuthor Commented:
thank you...it works perfectly...please email me the source code.

0
tecbuilderCommented:
program RomanNumeral;
uses Crt;

type str2 = string[2];

const
  valRN: array[1..13] of word = (1,4,5,9,10,40,50,90,100,400,500,900,1000);
  textRN: array[1..13] of str2 = ('I','IV','V','IX','X','XL','L','XC','C','CD','D','CM','M');

var
  ans: string;
  isOk: boolean;
  d, m: word;

procedure convertInteger(var T: string);
var
  N,                       { value that is being worked on }
  numRN, code: integer;
  i,j: byte;
  outRN: string;           { keeps track of letters }

begin
  Val(T, N, code);   { convert string value to number value }

  outRN := '';       { initialize }

  repeat
    i := 14;
    { Get the value in array that is just less than current value.}
    repeat
      dec(i);
    until valRN[i] <= N;

    { Get how many times the letter needs to be written. }
    numRN := N div valRN[i];

    { Write the letter. }
    for j := 1 to numRN do outRN := outRN + textRN[i];

    { The remainder is what needs to be worked on. }
    N := N mod valRN[i];
   until N = 0;

   T := 'The roman numeral for '+T+' is '+outRN;
end;

procedure convertRoman(var T: string);
const
  tmp1: array[1..7] of word = (1,5,10,50,100,500,1000);
  tmp2: array[1..7] of str2 = ('I','V','X','L','C','D','M');
var
  i,j: byte;
  ttl: word;                      { total value }
  RN: array[1..100] of word;      { seperates letters for analysis }
  tmp: string;
begin
  for i := 1 to 40 do RN[i] := 0;    { Initialize }

  ttl := 0;
  for i := 1 to length(T) do begin
    j := 8;

    { Get position of letter in the array. }
    repeat          
      dec(j);
    until tmp2[j] = T[i];

    { Assign value of letter. }
    RN[i] := tmp1[j];
  end;

  for i := 1 to length(T) do begin
    if i > 1 then begin

      { Add value of letter to the total value. }
      ttl := ttl + RN[i];

      { Need to re-evaluate number because number before current number
        is less than the current number.  For example:  IX = 10-1 = 9}
      if RN[i-1] < RN[i] then begin
        ttl := ttl - (RN[i-1]+RN[i]) ;
        ttl := ttl + (RN[i] - RN[i-1]);
      end;
    end
    else ttl := RN[i];
  end;

  { Convert number to string value. }
  Str(ttl, tmp);
  T := 'The numeric value for '+T+' is '+ tmp;
end;

var
  i: byte;
  done: boolean;
label alldone;
begin
  ClrScr; done := false;

  Writeln('Enter a zero (0) when done.'); Writeln;
  repeat
    Write('Enter a roman numeral or an integer --> ');
    Readln(ans);
    if ans = '0' then begin done := true; goto alldone; end;
    for i := 1 to length(ans) do ans[i] := Upcase(ans[i]);
    i := 1;

    { Validate user input. }
    repeat
                        { 0 - 9, I, V, X, C, D, L, M}
      if ord(ans[i]) in [48..57,73,86,88,67,68,76,77]
      then isOk := true
      else isOk := false;
      inc(i);
    until (i > length(ans)) or not isOk;

    if isOk then begin     { value entered is an integer or roman numeral }
      if ord(ans[1]) in [48..57]  { a numeric value was entered }
      then convertInteger(ans)
      else convertRoman(ans);
    end
    else ans := 'An invalid character was entered.';

    Writeln(ans);
    ReadKey;
    Writeln;

alldone:
  until done;
end.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.