M=1000  D=500  C=100  L=50  X=10  V=5  I=1
MDCLXVI = 1000 + 500 + 100 + 50 + 10 + 5 + 1 = 1666.
but i need to convert the given integer in the form of 1000,500,100,50,10,5 and 1s
can anyone please help on some logics as how to do it
convert decimal to roman
Given an integer i need to display the corresponding roman number
Page 1 of 14 Replies  15199 Views  Last Post: 28 December 2006  04:08 AM
Replies To: convert decimal to roman
#2
Re: convert decimal to roman
Posted 27 December 2006  04:10 AM
can you show us what code you've attempted thus far?
#3
Re: convert decimal to roman
Posted 27 December 2006  10:17 AM
first of all you need to figure out which is the greatest value a roman number can have. As you mention it is 1000 (M).
If your number is >= 1000, you will then need to display how many thousands it has, each time subtracting 1000 from your original number.
i.e
Then, with the same logic, use the displaysubtract method for the number being >= to 500, then >= 100, then >=50 and so on until your number reaches 0.
Try it out and post some code and we'll all definitely help you out here.
If your number is >= 1000, you will then need to display how many thousands it has, each time subtracting 1000 from your original number.
i.e
if (number >= 1000) { cout << "M"; number=1000; }
Then, with the same logic, use the displaysubtract method for the number being >= to 500, then >= 100, then >=50 and so on until your number reaches 0.
Try it out and post some code and we'll all definitely help you out here.
This post has been edited by may4life: 27 December 2006  10:18 AM
#4
Re: convert decimal to roman
Posted 28 December 2006  03:16 AM
The next step would be to contain this code in a loop until the number is no longer in that field.
i.e
After this you implement for 500, 100, 50 and so on until you get to the code
And that's it!! Decimal to Roman in no time. This is one way of doing it, im sure there are loads of other ways if you sit down n think a bit
i.e
while (number >= 1000) { if (number >= 1000) { cout << "M"; number=1000; } }
After this you implement for 500, 100, 50 and so on until you get to the code
while (number >= 1) { if (number >= 1) { cout << "I"; number=1; } }
And that's it!! Decimal to Roman in no time. This is one way of doing it, im sure there are loads of other ways if you sit down n think a bit
This post has been edited by may4life: 28 December 2006  03:17 AM
#5
Re: convert decimal to roman
Posted 28 December 2006  04:08 AM
Quote
And that's it!! Decimal to Roman in no time. This is one way of doing it, im sure there are loads of other ways if you sit down n think a bit
Well 1 way to do this, is use my c++ snippet that i added yesterday.
Page 1 of 1
