-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoman_numeral_converter.cpp
76 lines (57 loc) · 1.73 KB
/
Roman_numeral_converter.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
using namespace std;
int num,mill,cent,dece,unid = 0;
string msg = "Enter a number: ";
int main()
{
cout << msg;
cin >> num;
cout << endl;
unid = num % 10; num /= 10;
dece = num % 10; num /= 10;
cent = num % 10; num /= 10;
mill = num % 10; num /= 10;
switch(mill)
{
case 1: cout << "M"; break;
case 2: cout << "MM"; break;
case 3: cout << "MMM"; break;
}
switch(cent)
{
case 1: cout << "C"; break;
case 2: cout << "CC"; break;
case 3: cout << "CCC"; break;
case 4: cout << "CD"; break;
case 5: cout << "D"; break;
case 6: cout << "DC"; break;
case 7: cout << "DCC"; break;
case 8: cout << "DCCC"; break;
case 9: cout << "CM"; break;
}
switch(dece)
{
case 1: cout << "X"; break;
case 2: cout << "XX"; break;
case 3: cout << "XXX"; break;
case 4: cout << "XL"; break;
case 5: cout << "L"; break;
case 6: cout << "LX"; break;
case 7: cout << "LXX"; break;
case 8: cout << "LXXX"; break;
case 9: cout << "XC"; break;
}
switch(unid)
{
case 1: cout << "I"; break;
case 2: cout << "II"; break;
case 3: cout << "III"; break;
case 4: cout << "IV"; break;
case 5: cout << "V"; break;
case 6: cout << "VI"; break;
case 7: cout << "VII"; break;
case 8: cout << "VIII"; break;
case 9: cout << "IX"; break;
}
return 0;
}