
04-22-2004, 08:45 AM
|
|
|
easy roman numerals
could someone make this program actually do roman numerals.
Dim a As Integer
Dim b As Integer
Dim Digit As Integer
Dim RomanNumber As String
Dim RomanDigit As String
Roman = InputBox("Type in number", "Numerals", "X")
a = Len(Roman)
RomanNumber = Roman
RomanNumber = UCase(RomanNumber)
For b = a To 1 Step -1
RomanDigit = Mid$(RomanNumber, b, 1)
Select Case RomanDigit
Case "L"
Digit = 50
Case "C"
Digit = 100
Case "D"
Digit = 500
Case "M"
Digit = 1000
Case "X"
Digit = 10
Case "I"
Digit = 1
Case "V"
Digit = 5
Case Else
MsgBox ("Invalid Character")
End Select
firstnumeral = Digit
secondnumeral = secondnumeral + firstnumeral
If secondnumeral > firstnumeral Then
secondnumeral = secondnumeral - First
End If
Next
MsgBox "Numeral " & secondnumeral
|

04-22-2004, 05:23 PM
|
 |
Super Moderator
|
|
Join Date: Aug 2001
Location: Phoenix, Arizona
Posts: 2,781
|
|
Yeah... what language?
in java:
Code:
private static String RN(int number){
int[] nums = { 1000, 500, 100, 50, 10, 5, 4, 1};
String[] numerals = { "M", "D", "C", "L", "X", "V", "IV", "I"};
boolean done = false; int x = 0;
while(done == false && x < 8)
{
if(number >= nums[x]){
done = true;
return (numerals[x] + RN(number - nums[x]));
}
x++;
}
return "";
}
private static int number(String RN){
int[] vals = new int[RN.length()];
int total = 0;
for(int x = 0; x < RN.length(); x++)
vals[x] = val(RN.charAt(x));
for(int x = 0; x < RN.length() - 1; x++){
if(vals[x] < vals[x+1])
total -= vals[x];
else
total += vals[x];
}
total += vals[RN.length() - 1];
return total;
}
private static int val(char c){
int[] nums = { 1000, 500, 100, 50, 10, 5, 1};
char[] numerals = { 'M', 'D', 'C', 'L', 'X', 'V', 'I'};
for(int x = 0; x < 7; x++){
if(c == numerals[x])
return nums[x];
}
return 0;
}
__________________
It's not a car, it's an addiction.
The only carb that matters is under the hood.
There's an option for most vehicles that increases brake horsepower, increases mileage, increases driver control, lasts longer than the alternative, and even reduces the price of the vehicle. Despite all this, most people in this country choose the alternative, an automatic transmission.
|

04-22-2004, 07:50 PM
|
 |
Super Moderator
|
|
Join Date: Aug 2001
Location: Phoenix, Arizona
Posts: 2,781
|
|
The three methods are for turning a base 10 number into a Roman numeral, a Roman numeral into a base 10 number, and a method for the second method to find the value of an individual character.
I decided to test it and the first and third methods run completely fine, however the second method won't work properly... Can anyone figure out the flaw?
EDIT: Nevermind; I fixed it. I was going recursion-happy I think. Class has been affecting me I think with it influencing the way I program. 
__________________
It's not a car, it's an addiction.
The only carb that matters is under the hood.
There's an option for most vehicles that increases brake horsepower, increases mileage, increases driver control, lasts longer than the alternative, and even reduces the price of the vehicle. Despite all this, most people in this country choose the alternative, an automatic transmission.
|

04-23-2004, 09:45 AM
|
|
Platinium Techie
|
|
Join Date: Mar 2004
Location: Quantico, VA
Posts: 908
|
|
no, i think justin wants it in visual basic 6?
__________________
-Semper Fi
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:45 PM.
Powered by vBulletin® Version 3.6.5 Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
|