I want to ask if this is correct and will not make any mistake in coverting arabic numbers to roman numerals
Also I want to ask if it is better to use modulus operator.
Code:
{
int year;
cout<<"Enter a year: ";
cin>>year;
cout<<"The Roman Numeral equivalent of "<<year<<" is ";
while(year>=1000)
{
cout<<"M";
year=year-1000;
}
if(year>=900)
{
cout<<"CM";
year=year-900;
}
if(year>=500)
{
cout<<"D";
year=year-500;
}
if(year>=400)
{
cout<<"CD";
year=year-400;
}
while(year>=100)
{
cout<<"C";
year=year-100;
}
if(year>=90)
{
cout<<"XC";
year=year-90;
}
if(year>=50)
{
cout<<"L";
year=year-50;
}
if(year>=40)
{
cout<<"XL";
year=year-40;
}
while(year>=10)
{
cout<<"X";
year=year-10;
}
if(year>=9)
{
cout<<"IX";
year=year-9;
}
if(year>=5)
{
cout<<"V";
year=year-5;
}
while(year>=1)
{
cout<<"I";
year=year-1;
}
}