English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Is there an easier way of doing this:
I have to make a program thathe finish product would be that you can input a number and if you press the command button it would come out as Roman Numerals.......I was thinking of making a if then statment for every number but i realized it might take me a year to do that......is there another way to do it???

2007-02-12 01:17:30 · 3 answers · asked by y0ger_19 4 in Computers & Internet Programming & Design

3 answers

You need to logically work this through and do a series of if statements that reflect that logic.

Suppose I want to convert numbers up to 100 to roman. The logic is:

100 = C
90 -> 99 = XC + something
50 -> 89 = L + some Xs + something
40 -> 49 = XL + something
10 -> 39 = some Xs + something

the "something" is the units part, and I'm not going to go into that much detail (hey, I have a job to do too!)

So the code to convert a string num to a string roman might be:
roman = ""
if (num = 100) then
roman = "C"
num = 0
end if
if (num >= 90) then
roman = "XC"
num = num - 90 ' so we handle the something below
end if
if num >=50 then
roman = "L"
num = num - 50
end if
while (num > 10)
roman = roman & "X"
num = num - 10
end while

etc

2007-02-12 02:02:31 · answer #1 · answered by Meg W 5 · 2 0

I think Meg is on the right track. The one thing I might do different than her is to turn the number into a string and then check it character by character.

Say the number is 1234
dim strNumber as string
strNumber = "1234"

dim lenNumber as integer 'Length variable so you know how many characters to check in a loop
lenNumber = Len(strNumber)

dim temp as string

loop through...I'd go by Length descending

temp = mid(strNumber, lenNumber,1)

Then write your code blocks for each column

2007-02-12 03:11:06 · answer #2 · answered by rod 6 · 1 0

you can do a case select statement. case 1, then i..something like that. there might be another way, but it would be complicated. good luck!

2007-02-12 01:20:59 · answer #3 · answered by rchilly2000 5 · 0 1

fedest.com, questions and answers