1. Roman Numeral...T_T

i am very very very new to computer sicence thing...
converting number to roman numeral is kinda hard for me
i learned looping,branching,and strings
can u guys help me?

Code:
```#include<iostream>

using namespace std;

int main()
{
short x;

<<endl;
cin >> x;

if(x == 1)
{
cout << "I";
}
else if(x == 5)
{
cout << "V";
}
else if(x == 10)
{
cout << "X";
}
else if(x == 50)
{
cout << "L";
}
else if(x == 100)
{
cout << "C";
}
else if(x ==500)
{
cout << "D";
}
else if(x == 1000)
{
cout << "M";
}
else
{
cout << "error\n"
<<endl;
}

return 0;
}```

2. what are you having problems with?

3. converting 1 - 3999 but i dont know how to do it...

4. What is your algorithm, or at least what steps do you have in mind?

5. Hint: Many numbers use multiple characters when converted to roman numerals. Your current code will only ever output a single character, so you need to run that code over and over until all the correct characters are output.

6. Code:
```#include<iostream>
#include<string>
using namespace std;

int main()
{
short x;
string roman;

cin >> x;
while (!(x < 4000 && x > 0))   // I should probably DeMorgan's this...
{
cerr << "\n\aInvalid range!  Your value must be between 1 "
"and 3999!\nSo sayeth the Emperor!\n\n";
cin >> x;
}

// need to 'combine' things so that they can do non-exact multiples:  1776, 931, 452, 8, ...

if(x == 1000)
{
roman = "M";
}
else if(x == 500)
{
roman = "D";
}
else if(x == 100)
{
roman = "C";
}
else if(x == 50)
{
roman = "L";
}
else if(x == 10)
{
roman = "X";
}
else if(x == 5)
{
roman = "V";
}
else if(x == 1)
{
roman = "I";
}

// x/1000 = t;
// count << "M" * t <<endl;
// print out t amout of times

cout << x << " translated to Roman Numerals is " << roman << ".\n";
return 0;
}```
i only learned branching,looping,and string, and few basic things

how should i combine the things and do the non-exact number?

thank you for helping me

7. Can you write out in english how you would solve this problem. Convert 79 to roman numerals and write down each step. That will be the first part of writing the correct code.

8. yes.. convert 79,1234,874 ... ne numbers in to roman numeral

9. You have already described the problem. What you should do now is come up with a solution.

For example, suppose I want to give converting 16 to Roman numerals as an example towards getting a general solution. I might think:
16 >= 10, so I need an X.
16 - 10 = 6.
Now, 6 >= 5, so I need a V.
6 - 5 = 1.
1 is just I.
Thus 16 is XVI.

So, how would you solve it if you are given 79? What about say, 2007?

10. It's much like converting numbers to other bases, such as binary, if you've ever done that (well, it's similar to one way of doing it). Take out the largest number you can. Repeat until you have zero.

11. oh ok ty guys^^ it was very helpful^^ ill try to do it now

12. Originally Posted by dwks
It's much like converting numbers to other bases, such as binary, if you've ever done that (well, it's similar to one way of doing it). Take out the largest number you can. Repeat until you have zero.
Close but not quite. You have to consider numbers like 4. The roman numberal IV contains V which is larger than 4.

13. It would certainly be an interesting algorithm to write, have fun doing it!