# C++ conversion

• 09-05-2001
charlie
C++ conversion
In general Roman numberals can be converted mathmatically
to their arabic equivalent by simply assiging a numerical value
to each letter, according to the chart below, and calculating a total.

M=1000|D=500|C=100|L=50|X=10|V=5|I=1

In code, could you show me how to along with comments convert
• 09-05-2001
zen
What bit are you stuck on?
• 09-05-2001
master5001
As zen pointed out you are well on your way here. There are many ways to do this. But what the hell, here are a few:
Code:

```/* way number one */ #define M 1000 #define D 500 #define C 100 //you ge the idea /* way number two */ short M = 1000, D = 500, C = 100; //not too hard```
There are also enumerations. You could also slap together some macros or functions to do simple opporations such as V + I = VI. But you will have make a function that returns a string for that sort of answer.
• 09-05-2001
minime6696
easyness
Well... think about it... just set up a loop to go along and pick up letterz:

Code:

``` #include <windows.h> #include <stdio.h> #define M 1000 #define D 500 #define C 100 int RomanToAribic(char *string) {     int ret = 0;     for( int sloop = 0 ; sloop<strlen(string) ; sloop++ )     {           switch(toupper(string[sloop]))           {                 case 'M': ret += M; break;                 case 'D': ret += D; break;                 case 'C': ret += C; break;                 default: break;           }     } } void main() {         char rom[255];         printf("Enter a roman number and I will spit back Aribic:");         int r = RomanToAribic(rom);         printf("\n%i",r); // If I got it wrong and its * instead of + or something please correct me. :) }```
SPH
• 09-05-2001
Stoned_Coder
I dont want to spoil your party but that wont work minime. You see there is a catch with roman numerals and that is CD is not DC yet to your code it is. so its slightly more complicated than that.
• 09-05-2001
minime6696
okay
I asked to correct me if im wrong... so how does it work then?

SPH
• 09-05-2001
Govtcheez
For example...

LX is 60
XL is 40

If the preceding number is smaller, that many is subtracted... get it?