Decimal to Roman numeral conversion algorithm I have written a program to convert a decimal to a Roman numeral. I am wondering if my algorithm is okay or not. If it's not okay, I want suggestions on improving my code. This code only works for inputs up to 5000. I found this question in a code cracker competition at my college.

#include &lt;iostream&gt;
using namespace std;
int main()
{
    int num=0;
    int user;
    int temp=0;
    string ans[4];
    int mod=10;
    int n[5];
    string r1[]={"0","I","II","III","VI","V","VI","VII","VIII","IX" };
    string r2[]={"x","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
    string r3[]={"C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
    string r4[]={"M","MM","MMM","MMMM"};

    cout&lt;&lt;"Enter Number"&lt;&lt;endl;
    cin&gt;&gt;user;

    for(int i=0;i&lt;4;i++)
{
    num=user%mod;
    user=user-num;
    n[3-i]=num;
    mod=mod*10;
}

for(int i=0;i&lt;4;i++)
{
    if(n[i]&gt;999)
    {
        temp=n[i]/1000;
        ans[i]=r4[temp-1];
    }
    if(n[i]&gt;99 &amp;&amp; n[i]&lt;1000)
    {
        temp=n[i]/100;
    ans[i]=r3[temp-1];
    }
    if(n[i]&gt;9&amp;&amp; n[i]&lt;100)
    {
    temp=n[i]/10;
    ans[i]=r2[temp-1];
    }
        if(n[i]&gt;0 &amp;&amp; n[i]&lt;10)
    {
    temp=n[i];
    ans[i]=r1[temp];
    }
    }
    for(int i=0;i&lt;4;i++)
    {
    cout&lt;&lt;ans[i];
    }
    return 0;
    }
This code has a bug as 14 and 16 give the same output, while the Roman representation for them should surely be different:


14 -> XVI
16 -> XVI