|
Pages: [1] 2
|
 |
|
Author
|
Topic: Converting numbers into roman numerals.. (Read 6589 times)
|
dave
New Member
Posts: 4
|
I was wondering if anyone had an easy way I could go at this...
I need to go up to 2003, and I could do it in 2027 lines of code [bunch of if statements, lol] but I know you could do it with a DO loop.
If anyone has any ideas for me, please reply.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
|
|
|
|
|
|
|
relsoft
*/-\*
    
Posts: 3924

|
I need to go up to 2003, and I could do it in 2027 lines of code [bunch of if statements, lol] but I know you could do it with a DO loop. Sounds suspiciously like: IF num$ = 1 THEN PRINT "I" IF num$ = 2 THEN PRINT "II" ... IF num$ = 2003 THEN PRINT "MMIII" :rotfl: Dang!!! I just remembered that I posted something like that for an odd even number problem. Welcome to the club!!!
|
|
|
|
|
Logged
|
|
|
|
|
|
dave
New Member
Posts: 4
|
First off I was just gonna do it in an array with all the set roman numerals like M, D, L, V etc...and whenever it wasnt one of those then do the math to get the number..
I had like
DIM ones$(9) LET ones$(1) = "I" LET ones$(2) = "II" LET ones$(3) = "III" ....
DIM hundreds$(900) .... LET hundreds$(500) = "M" ....
you get the point.
|
|
|
|
|
Logged
|
|
|
|
|
|
dave
New Member
Posts: 4
|
Agamemnus's program is great..
Thanks for the tip, too.
|
|
|
|
|
Logged
|
|
|
|
|
|
Antoni Gual
Na_th_an
    
Posts: 1433

|
DECLARE SUB roman (a%, I%) ' DIM SHARED b$ b$ = "IVXLCDM" DO DO INPUT "Enter an integer >0 and <4000 (0 to exit)"; a% IF a% < 1 THEN END LOOP UNTIL a% < 4000 PRINT roman a%, 1 PRINT LOOP END
SUB roman (a%, I%) IF a% = 0 THEN EXIT SUB n% = a% MOD 10 roman a% \ 10, I% + 2 SELECT CASE n% CASE 9: PRINT MID$(b$, I%, 1) + MID$(b$, I% + 2, 1); CASE 8, 7, 6: PRINT MID$(b$, I% + 1, 1) + STRING$(n% - 5, ASC(MID$(b$, I%, 1))); CASE 5: PRINT MID$(b$, I% + 1, 1); CASE 4: PRINT MID$(b$, I%, 1) + MID$(b$, I% + 1, 1); CASE 3, 2, 1: PRINT STRING$(n%, ASC(MID$(b$, I%, 1))); END SELECT END SUB
|
|
|
|
|
Logged
|
Antoni
|
|
|
|
|
|
|
|
Pages: [1] 2
|
|
|
|
|