Hello, im new. And I'm kinda stumped. We were given an exercise to do in which the user enters a number in roman numerals and the program converts it to decimal numbers. I have no problem convert if the number given is in the right order from the largest to the least like 23 XXIII, but in some cases like for example 4 = IV, the 4 came before the five, or 90 = XC; I did it with two switches so I can compare the adjacent numbers. But theres a problem I can't explain it but if u look at the code mayb u'll understand. Heres the method I wrote but as u can see I did't complete it but the important part of the code is there I'm just stuck here. If any1 has an idea how to fix this problem I appreciate it. Oh yea to calculate the roman numerals u add the numbers together like XX = 10 +10 =20; or MDCXII = 1000+500+100+20+1+1 = 1622; but numbers like 90 and 4 and all the other exceptions u calculate it like this ex.
XC = 10+100 = 110 – (2*10) = 90;
IV = 1+5 = 6 – (2*1)= 4;
U add them like u add the other ones but then you subtract from it 2 times the number that is ahead like in the of case the 90 its 10 and in the case of the 4 its 1.

So I'd really appreciate any ideas u can give me. I just want an idea. Thanx J.

_public void convertRoman(String numRom) //method to convert the roman numerals to decimal numbers and store
_{_____________ // it as that
__int tempDec=0;
__int valueOfR =0;
__int length = numRom.length();
__int first,second;
__
__for(int i=0; i<length-1; i++)
__{
______
___switch ( numRom.characterAt(i))
___{
____case 'M': case 'm': valueOfR = 1000; break;
____case 'D': case 'd': valueOfR = 500; break;
____case 'C': case 'c': valueOfR = 100; break;
____case 'L': case 'l': valueOfR = 50; break;
____case 'X': case 'x': valueOfR = 10; break;
____case 'V': case 'v': valueOfR = 5; break;
____case 'I': case 'i': valueofR = 1; break;
___}_ first = valueOfR;
___
___switch ( numRom.characterAt(i+1))
___{
____case 'M': case 'm': valueOfR = 1000; break;
____case 'D': case 'd': valueOfR = 500; break;
____case 'C': case 'c': valueOfR = 100; break;
____case 'L': case 'l': valueOfR = 50; break;
____case 'X': case 'x': valueOfR = 10; break;
____case 'V': case 'v': valueOfR = 5; break;
____case 'I': case 'i': valueofR = 1; break;
___} second = valueOfR;
____
___second = first + second;
___if (first >second)
___ _tempDec = tempDec + second;}
_}

ok im done but i don't get the code wrappin thing!?

thanx !! :)
i didn't really read that well but it looks helpful. is it from a book?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.