Qbasicnews.com
September 25, 2017, 01:50:59 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Converting numbers into roman numerals..  (Read 14336 times)
dave
New Member

Posts: 4


WWW
« on: September 11, 2003, 04:38:38 PM »

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
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #1 on: September 11, 2003, 06:18:02 PM »

http://www.geocities.com/pisforpi/flyingsoft

"Roman Numerals". Downloads section. Has source code.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #2 on: September 11, 2003, 07:38:28 PM »

Quote from: "dave"
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:

Code:
IF num$ = 1 THEN PRINT "I"
IF num$ = 2 THEN PRINT "II"
...
IF num$ = 2003 THEN PRINT "MMIII"


:rotfl:
Logged

dave
New Member

Posts: 4


WWW
« Reply #3 on: September 11, 2003, 09:53:59 PM »

you got it Tongue
Logged
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #4 on: September 11, 2003, 11:12:25 PM »

Woah, you didn't do all of it by hand, did you?
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #5 on: September 11, 2003, 11:36:04 PM »

My program is 100% bug free....
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #6 on: September 12, 2003, 03:08:13 AM »

Quote from: "oracle"
Quote from: "dave"
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:

Code:
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

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #7 on: September 12, 2003, 04:35:50 AM »

I remember that!

Code:
IF num = 1 THEN PRINT "Odd."
IF num = 2 THEN PRINT "Even."
IF num = 3 THEN PRINT "Odd."
...
IF num = 600000 THEN PRINT "Even."


:rotfl:

I seem to recall that the person asking for it had trouble compiling it ;*)
Logged

dave
New Member

Posts: 4


WWW
« Reply #8 on: September 12, 2003, 07:24:59 AM »

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
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #9 on: September 12, 2003, 08:22:56 PM »

Nightmare... :lol:

Is agamemnus's program good for you?

ps: LET is ancient. You can completely omit the word LET in front of a variable, and QB will understand.
Logged

dave
New Member

Posts: 4


WWW
« Reply #10 on: September 14, 2003, 05:20:03 PM »

Agamemnus's program is great..

Thanks for the tip, too.
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #11 on: September 14, 2003, 08:45:28 PM »

Great, I'm glad my program has made a difference in the world. Smiley
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #12 on: September 17, 2003, 06:38:07 AM »

Code:

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
Neo
Na_th_an
*****
Posts: 2150



« Reply #13 on: September 17, 2003, 07:39:12 AM »

Looks great! Only beware that QB doesn't have such a good stack-handler so don't recurse too much... Tongue
Logged
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #14 on: September 17, 2003, 07:41:17 AM »

Three levels is not too much... It would be different if i was calculating a factorial Cheesy
Logged

Antoni
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!