Weekly Qbasic and Qb64 Lesson Topics
April 18, 2024, 06:50:36 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Dustie Bear.

Pages: [1]
  Print  
Author Topic: Dustie Bear.  (Read 530 times)
Dustie Bear
Full Member
***
Posts: 115


« on: April 21, 2011, 12:11:59 pm »

A program to change numbers into Roman Numerals

Prints Roman Numerals in large text centered on screen!

There are some notes in the program that explain how Roman
Numerals work.

Code:
' Following information came from:
' http://www.onlineconversion.com/roman_numerals_advanced.htm


'      ___________ RULES OF USING ROMAN NUMERALS UP TO 4999 ____________

' --- A smaller number in front of a larger number means subtraction, all
'     else means addition. For example, IV means 4, VI means 6.

' --- You would not put more than one smaller number in front of a larger
'     number to subtract. For example, IIV would not mean 3.

' --- You must separate ones, tens, hundreds, and thousands as separate
'     items. That means that 99 is XCIX, 90 + 9, but never should be
'     written as IC. Similarly, 999 cannot be IM and 1999 cannot be MIM.

'I = numeral one. II is two, III is three. You seldom
'    see IIII as 4, since IV can also mean 4, plus its shorter to write.

'V = numeral 5. IV is 4, VI is 6, VII is 7, VIII is 8.
'X = numeral 10. IX is 9, XI is 11, etc.
'L = numeral 50. XL would be 40.
'C = numeral 100. Think of Century having a hundred years. C is
'    short for the Latin word Centum, but that's not very easy to
'    remember.

'D = numeral 500.
'M = numeral 1000.

' You seldom see IIII as 4, since IV can also mean 4, plus its
'  shorter to write.
'
' Sometimes you will see a numeral with a line over it. That means
' to multiply it by 1000. A numeral V with a line over it means 5000
'
'  Since ASCII codes don't have letters as such Over
' score Characters.  MMMM = 4000 is not normal but we
' are using it anyway.
'______________________________________________________


DIM BigTxt(155, 13) AS LONG
DIM N AS INTEGER

SCREEN _NEWIMAGE(640, 480, 256)

DO
   ' ___ User Input ___
   a$ = ""
   DO WHILE a$ = ""
      CLS: LOCATE 10, 25
      LINE INPUT "Enter a Number > 0 and < 5000! "; a$: N = LEN(a$)
      IF LCASE$(a$) = "q" THEN SYSTEM
      IF VAL(a$) > 4999 THEN
         LOCATE 12, 11: PRINT "Number must be < 5000! ,,,,  Try again.";
         a$ = "": SLEEP
      END IF
   LOOP

   ' ___ Format Columns ___
   IF LEN(a$) = 1 THEN a$ = "   " + a$ ' ---1
   IF LEN(a$) = 2 THEN a$ = "  " + a$ '  --21
   IF LEN(a$) = 3 THEN a$ = " " + a$ '   -321

   ' Thousands column
   IF MID$(a$, 1, 1) = "1" THEN B$ = B$ + "M"
   IF MID$(a$, 1, 1) = "2" THEN B$ = B$ + "MM"
   IF MID$(a$, 1, 1) = "3" THEN B$ = B$ + "MMM"
   IF MID$(a$, 1, 1) = "4" THEN B$ = B$ + "MMMM" '<-- Not normal format

   ' Hundreds column
   IF MID$(a$, 2, 1) = "1" THEN B$ = B$ + "C"
   IF MID$(a$, 2, 1) = "2" THEN B$ = B$ + "CC"
   IF MID$(a$, 2, 1) = "3" THEN B$ = B$ + "CCC"
   IF MID$(a$, 2, 1) = "4" THEN B$ = B$ + "CD"
   IF MID$(a$, 2, 1) = "5" THEN B$ = B$ + "D"
   IF MID$(a$, 2, 1) = "6" THEN B$ = B$ + "DC"
   IF MID$(a$, 2, 1) = "7" THEN B$ = B$ + "DCC"
   IF MID$(a$, 2, 1) = "8" THEN B$ = B$ + "DCCC"
   IF MID$(a$, 2, 1) = "9" THEN B$ = B$ + "CM"

   ' Tens column
   IF MID$(a$, 3, 1) = "1" THEN B$ = B$ + "X"
   IF MID$(a$, 3, 1) = "2" THEN B$ = B$ + "XX"
   IF MID$(a$, 3, 1) = "3" THEN B$ = B$ + "XXX"
   IF MID$(a$, 3, 1) = "4" THEN B$ = B$ + "XL"
   IF MID$(a$, 3, 1) = "5" THEN B$ = B$ + "L"
   IF MID$(a$, 3, 1) = "6" THEN B$ = B$ + "LX"
   IF MID$(a$, 3, 1) = "7" THEN B$ = B$ + "LXX"
   IF MID$(a$, 3, 1) = "8" THEN B$ = B$ + "LXXX"
   IF MID$(a$, 3, 1) = "9" THEN B$ = B$ + "XC"

   ' Ones column
   IF MID$(a$, 4, 1) = "1" THEN B$ = B$ + "I"
   IF MID$(a$, 4, 1) = "2" THEN B$ = B$ + "II"
   IF MID$(a$, 4, 1) = "3" THEN B$ = B$ + "III"
   IF MID$(a$, 4, 1) = "4" THEN B$ = B$ + "IV"
   IF MID$(a$, 4, 1) = "5" THEN B$ = B$ + "V"
   IF MID$(a$, 4, 1) = "6" THEN B$ = B$ + "VI"
   IF MID$(a$, 4, 1) = "7" THEN B$ = B$ + "VII"
   IF MID$(a$, 4, 1) = "8" THEN B$ = B$ + "VIII"
   IF MID$(a$, 4, 1) = "9" THEN B$ = B$ + "IX"

   ' ___ Center Text ___
   LenTxt = LEN(B$) / 2
   LenTxt = 44 - LenTxt
   LOCATE 12, LenTxt: COLOR _RGB(0, 0, 50)
   PRINT B$;
   B$ = ""

   ' ___ Get Small Numerals ___
   t = 0: tt = 0
   FOR B = 268 TO 420
      t = t + 1
      FOR bb = 176 TO 189
         tt = tt + 1
         IF tt > 13 THEN tt = 1
         BigTxt(t, tt) = POINT(B, bb)
      NEXT bb
   NEXT B
   CLS
   ' ___ Print Big Numerals ___
   t = 0: tt = 0
   FOR B = 32 TO 184
      t = t + 1
      FOR bb = 60 TO 73
         tt = tt + 1
         IF tt > 13 THEN tt = 1
         IF BigTxt(t, tt) = _RGB(0, 0, 50) THEN
            LINE (B * 3, 3 * bb)-(B * 3 + 2, 3 * bb + 2), 4, BF
         ELSE
            LINE (B * 3, 3 * bb)-(B * 3 + 2, 3 * bb + 2), 7, BF
         END IF
      NEXT bb
   NEXT B

   ' ___ Information ___
   COLOR 15: LOCATE 10, 30
   PRINT "Number you entered is :"; a$;
   LOCATE 17, 25
   PRINT "Press a key to do another one!";
   LOCATE 20, 35
   PRINT "'q' = quit"; ";"
   _DISPLAY

   ' ___ Wait for input ___
   a$ = "": DO WHILE INKEY$ <> "": LOOP
   DO WHILE a$ = ""
      a$ = INKEY$
      IF LCASE$(a$) = "q" THEN SYSTEM
   LOOP


LOOP
SYSTEM


« Last Edit: April 21, 2011, 12:22:22 pm by Dustie Bear » Report Spam   Logged

Share on Facebook Share on Twitter

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #1 on: April 21, 2011, 06:53:08 pm »

I did see this dusty, actually afew days ago, pretty neat,
It seems like the same code or principles in this could be used in alot of things,...
from Garry
Report Spam   Logged

Dustie Bear
Full Member
***
Posts: 115


« Reply #2 on: April 21, 2011, 11:01:28 pm »


Hi

Yes it has a few things that could be used in other ways
perhaps.

Feel free to mess with it.

Thanks
Dustie
Report Spam   Logged
Quark
Post Demos
*
Posts: 14


« Reply #3 on: June 14, 2011, 12:29:45 am »

I have read that mathematical calculations that were equivalent in difficulty to upper level college work for the Romans became grammar school stuff after the development of the decimal system.

Interesting to wonder what we do that's hard which would be easy with a different method.

--Quark
Report Spam   Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy