# Roman Numeral^^

• 04-16-2007
only1st
Roman Numeral^^
haha thnx to u guys i got this thing to work but there is a one problem

i dont know how to change 4 to IV

when i type 4 it comes out like IIII

4,9,40,90 ....

Code:

```while (x != 0)         if (x >= 1000)         {                 x = x - 1000;                 cout << "M";         }         else if (x >= 500)         {                 x = x - 500;                 cout << "D";         {         else if (x >= 100)         {                 x = x - 100;                 cout << "C";         {         else if (x > 50)         {                 x = x-50;                 cout << "L";         }         else if (x >= 10)         {                 x = x - 10;                 cout << "X";         }         else if (x >= 5)         {                 x = x - 5;                 cout << "V";         }         else if (x >= 1)         {                 x = x - 1;                 cout << "I";         } }```
• 04-16-2007
brewbuck
Quote:

Originally Posted by only1st
when i type 4 it comes out like IIII

Well obviously, considering your code doesn't look for 4, or 8, or 9, or any of the other special cases.
• 04-16-2007
Salem
4 and 9 are also special.
• 04-16-2007
only1st
yes i didnt put it in my code cause i dont know... so can u guys give me some ideas? plzzzzz
• 04-16-2007
Daved
This is why it would be better to write out your algorithm in english first, before you start coding. That way you can see holes in your implementation even before you start.

Forget a C++ program, how would you do the conversion in your head or with paper? How would you do it with 4? How about 9? And how about 79? Once you write that out in english, and maybe even post it here, we can help further.
• 04-16-2007
only1st
oh ok daved ty^^ ill try it
• 04-19-2007
only1st
haha thanx to u guys i finally finished my program once agin thnx