Quantcast
Channel: Java Question Bank » Cpp Programs
Viewing all articles
Browse latest Browse all 22

A C++ Program to convert the Roman numeral into an Arabic Integer

$
0
0

****************************************************************************************************************************************************

A C++ Program to convert the Roman numeral into an Arabic Integer

****************************************************************************************************************************************************

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream.h>
#include<conio.h>
void main()
{
char s[10];
int sum=0,i=0;
clrscr();
cout<<"Enter the roman numeral :";
cin>>s;
while(s[i]!='')
{
switch(s[i])
{
case 'm':sum+=1000;
break;
case 'd':if(s[i-1]=='c')
sum+=400;
else if(s[i-1]=='l')
sum+=450;
else
sum+=500;
break;
case 'c':if(s[i+1]!='d')
{
if(s[i-1]=='l')
sum+=50;
else
sum+=100;
}
break;
case 'l':if(s[i+1]!='c')
sum+=50;
break;
case 'x':if(s[i-1]=='i')
sum+=9;
else
sum+=10;
break;
case 'v':if(s[i-1]=='i')
sum+=4;
else
sum+=5;
break;
case 'i':if(s[i+1]!='x' || s[i+1]!='v')
sum+=1;
break;
default :cout<<"Invalid Roman numeral arises :";
}
i++;
}
cout<<"The equivalent Arabic integer is :"<<sum;
getch();
}

/*    OUTPUT
------
Enter the roman numeral :mdlvi
The equivalent Arabic integer is :1556
*/

15 total views, 15 views today


Viewing all articles
Browse latest Browse all 22

Trending Articles