Coverting integers to roman numerals!!! PLZ help

Write a program that accepts a year written as a 4-digit Arabic numeral and
outputs the year written in Roman numerals. Some important Roman numerals are V
for 5, X for 10, L for 50, C for 100, D for 500, and M for 1000. Some numbers are
formed by using some kind of subtraction where a lesser-valued numeral is written left
of a higher-valued one. The lesser-valued is then subtracted from the higher-valued one.
For example: IV becomes 4, CM becomes 900, etc. Your program should include a loop
that allows the user play again until he or she is done.

the sad thing is this is one of many i had to do, last night i started this and apparently didnt save so all the code i have is from when i started... and now im screwed, would love input on a direction to move towards too. last night i slept 2 hours and i have done 5 other programs that are a part of this as a lab, if I don't get help I'm screwed. Have wife, kids, job and college, which is the reason why im behind...

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<iostream>
using namespace std;
int main()
{   int n;
    char answer = ' ';

    cout <<"\nDue to the nature of roman numerals\nthey have diverse characters to represent\nArabic numerals, Most are covered, but\nNumbers higher from 4000 to 10000 have\ncharacters not in Ascii, example 4000 would be\nIV with a line on top, just like a regular\nroman 4, to fix this problem I have put a '-'\nin front representing the top line.\nKnowing this, would you like to continue?(Y/N): ";
    cin >> answer;
    answer = toupper(answer);




     if(answer == 'Y' && answer != 'N')
     {Scary:

     cout << "\nEnter the number you want converted: ";
     while(cin>>n)
     {
     int i,j,k,l;
     l=(n/1000)*1000;
     if(l==1000)
          cout<<"M";
     if(l==2000)
          cout<<"MM";
     if(l==3000)
          cout<<"MMM";
     if(l==4000)
          cout<<"-IV";
     if(l==5000)
          cout<<"-V";
     if(l==6000)
          cout<<"-VI";
     if(l==7000)
          cout<<"-VII";
     if(l==8000)
          cout<<"-VIII";
     if(l==9000)
          cout<<"-IX";
     if(l==10000)
          cout<<"-X";
     k=(n%1000);
     k=(k/100)*100;
     if (k == 100)
		 cout<<"C";
	else if (k == 200)
		 cout<<"CC";
	else if (k == 300)
		 cout<<"CCC";
	else if (k == 400)
		 cout<<"CD";
	else if (k ==500)
		 cout<<"D";
	else if (k == 600)
		 cout<<"DC";
	else if (k == 700)
		 cout<<"DCC";
	else if (k ==800)
		 cout<<"DCCC";
	else if (k == 900)
		 cout<<"CM";
     k=n%1000;
     l=k%100;
     j=(l/10)*10;
     if (j == 10)
		 cout<<"X";
	else if (j == 20)
		 cout<<"XX";
	else if (j == 30)
		 cout<<"XXX";
	else if (j == 40)
		 cout<<"XL";
	else if (j ==50)
		 cout<<"L";
	else if (j == 60)
		 cout<<"LX";
	else if (j == 70)
		 cout<<"LXX";
	else if (j ==80)
		 cout<<"LXXX";
	else if (j == 90)
		 cout<<"XC";
     i=l%10;
     if (i == 1)
		 cout<<"I";
	else if (i == 2)
		 cout<<"II";
	else if (i == 3)
		 cout<<"III";
	else if (i == 4)
		 cout<<"IV";
	else if (i ==5)
		 cout<<"V";
	else if (i == 6)
		 cout<<"VI";
	else if (i == 7)
		 cout<<"VII";
	else if (i ==8)
		 cout<<"VIII";
	else if (i == 9)
		 cout<<"IX";
		 cout<<endl;

    cout <<"\nWould you like to try again?(Y/N): ";
    cin >> answer;
    answer = toupper(answer);

    if(answer == 'Y' && answer != 'N'){goto Scary;}
    else if(answer == 'N' && answer != 'Y'){return 0;}
     }

     }
     return 0;
}
Last edited on
I just posted what I had at sometime last night, i'll try to work up on it, if i update ill post more code...

Update:

this is what I came up with after a couple of hours, feel free to use it if you need it, numbers over 4000 can be fixed by making all values after that M which equals 1000... example 9000 = MMMMMMMMMM, hope it helps anyone...
Last edited on
Topic archived. No new replies allowed.