Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numbers To Roman Numerals
#1
This can use numbers from 1 to 3999. It stops there because 4000 and above use Roman Numerals with lines on top of the letters, which are hard to make with QB64.
Thanks to ChatGPT for helping me out on this one. I re-organized it a bit, etc. 

Code: (Select All)

'Thanks to ChatGPT for a little help figuring this out. I fixed the DIM numbers and removed the Function and made the code simpler.
'By SierraKen on Aug. 12, 2024
'I been wanting to make this since the 1990's! LOL

Dim values(13) As Integer
Dim symbols(13) As String

_Title "Numbers To Roman Numerals Converter"

Cls

start:

Input "Enter a number (1-3999): ", number

If number < 1 Or number > 3999 Then
    Print "Number out of range. Please enter a number between 1 and 3999."
Else

    values(1) = 1000: symbols(1) = "M"
    values(2) = 900: symbols(2) = "CM"
    values(3) = 500: symbols(3) = "D"
    values(4) = 400: symbols(4) = "CD"
    values(5) = 100: symbols(5) = "C"
    values(6) = 90: symbols(6) = "XC"
    values(7) = 50: symbols(7) = "L"
    values(8) = 40: symbols(8) = "XL"
    values(9) = 10: symbols(9) = "X"
    values(10) = 9: symbols(10) = "IX"
    values(11) = 5: symbols(11) = "V"
    values(12) = 4: symbols(12) = "IV"
    values(13) = 1: symbols(13) = "I"

    romanNum$ = ""
    num = number
    For i = 1 To 13
        While num >= values(i)
            romanNum$ = romanNum$ + symbols(i)
            num = num - values(i)
        Wend
    Next i

    Print "Roman Numeral: "; romanNum$
End If

Print: Print: Print
GoTo start:

Reply


Messages In This Thread
Numbers To Roman Numerals - by SierraKen - 08-14-2024, 01:25 AM



Users browsing this thread: 2 Guest(s)