Techware Labs Header

Forums have moved

See this announcement for more details, or just go directly there.

  #1  
Old 04-22-2004, 08:45 AM
Hammmy
 
Posts: n/a
Default 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
Reply With Quote
  #2  
Old 04-22-2004, 05:23 PM
vee_ess's Avatar
vee_ess vee_ess is offline
Super Moderator
 
Join Date: Aug 2001
Location: Phoenix, Arizona
Posts: 2,781
Send a message via ICQ to vee_ess Send a message via AIM to vee_ess Send a message via MSN to vee_ess Send a message via Yahoo to vee_ess
Default

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;
}
Reply With Quote
  #3  
Old 04-22-2004, 07:50 PM
vee_ess's Avatar
vee_ess vee_ess is offline
Super Moderator
 
Join Date: Aug 2001
Location: Phoenix, Arizona
Posts: 2,781
Send a message via ICQ to vee_ess Send a message via AIM to vee_ess Send a message via MSN to vee_ess Send a message via Yahoo to vee_ess
Default

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.
Reply With Quote
  #4  
Old 04-23-2004, 09:45 AM
Dragon Dragon is offline
Platinium Techie
 
Join Date: Mar 2004
Location: Quantico, VA
Posts: 908
Default

no, i think justin wants it in visual basic 6?
__________________
-Semper Fi
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:09 AM. Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Forum style by ForumMonkeys.