[Solved] c# How to convert Roman Number to Number [Vice versa] [closed]


This should help u 🙂

static void Main(string[] args)
    {
        string roman = Console.ReadLine();

        int tens = 0;

        int current_index = 0;
        for (int i = 0; i < roman.Length; i++)
        {
            if (roman[i] == 'X')
                tens++;
            else
            {
                current_index = i;
                break;
            }
        }
        int result = 0;
        switch (roman.Substring(current_index))
        {
            case "I" :
                result = (tens * 10) + 1;
                break;
            case "II" :
                result = (tens * 10) + 2;
                break;
            case "III" :
                result = (tens * 10) + 3;
                break;
            case "IV" :
                result = (tens * 10) + 4;
                break;
            case "V" :
                result = (tens * 10) + 5;
                break;
            case "VI" :
                result = (tens * 10) + 6;
                break;
            case "VII" :
                result = (tens * 10) + 7;
                break;
            case "VIII" :
                result = (tens * 10) + 8;
                break;
            case "IX" :
                result = (tens * 10) + 9;
                break;
        }
        Console.WriteLine(result);
        Console.ReadLine();
    }

Hope it helps 🙂

2

solved c# How to convert Roman Number to Number [Vice versa] [closed]