Welcome, Guest. Please login or register.
March 29, 2017, 08:02:34 AM
Home Help Search Login Register
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base

Qbasicnews.com  |  QBasic  |  QB Discussion & Programming Help  |  Topic: Converting numbers into roman numerals.. « previous next »
Pages: [1] 2 Print
Author Topic: Converting numbers into roman numerals..  (Read 13438 times)
dave
New Member

Posts: 4



WWW
Converting numbers into roman numerals..
« 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



Converting numbers into roman numerals..
« 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
Re: Converting numbers into roman numerals..
« 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
Converting numbers into roman numerals..
« Reply #3 on: September 11, 2003, 09:53:59 PM »

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



Converting numbers into roman numerals..
« 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



Converting numbers into roman numerals..
« 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
Re: Converting numbers into roman numerals..
« 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
Converting numbers into roman numerals..
« 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
Converting numbers into roman numerals..
« 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
Converting numbers into roman numerals..
« 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
Converting numbers into roman numerals..
« 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



Converting numbers into roman numerals..
« 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
Converting numbers into roman numerals..
« 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



Converting numbers into roman numerals..
« 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
Converting numbers into roman numerals..
« 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 
Qbasicnews.com  |  QBasic  |  QB Discussion & Programming Help  |  Topic: Converting numbers into roman numerals.. « previous next »
Jump to:  


Login with username, password and session length

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