Techwarelabs Community

Techwarelabs Community (https://www.techwarelabs.com/community/index.php)
-   Software - Applications, Programming, and Games (https://www.techwarelabs.com/community/forumdisplay.php?f=13)
-   -   easy roman numerals (https://www.techwarelabs.com/community/showthread.php?t=9416)

Hammmy 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

vee_ess 04-22-2004 05:23 PM

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;
}


vee_ess 04-22-2004 07:50 PM

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. :sick:

Dragon 04-23-2004 09:45 AM

no, i think justin wants it in visual basic 6?


All times are GMT -5. The time now is 08:15 PM.

Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.