# Help with a c++ program that converts numbers 1 to 1000

1. Mar 16, 2009

### mulabisc

I have tried to come up with the code below so i want to improve it so tha it converts numbers 1 to 1000 to romans.. help out!!!

#include <iostream>
using namespace std;

int main()
{

int n;
n >=1;

cout<< "please enter an interger number:" <<endl;
cin >> n;

if(n == 9)

cout << "IX";

else if(n >=5 && n<=8)

cout << "V";

else if (n == 4)

cout << "IV";

else if(n >=1 && n <=3)

cout << "I";

return 0;
}

2. Mar 16, 2009

### rootX

http://maryt.files.wordpress.com/2007/03/roman_numerals_complete.jpg [Broken]

It says

10 - X
50 - L
100 - C
500 - D
1000 - M

and second thing to notice is

20 = XX
30 = XXX
40 = XL

60 = LX
70 = LXX
80 = LXXX
90 = XC

and numbers from 1 to 9 just use I,II,III, .. with a prefix
like 20 = XX
and 21 = "XX"+ "I"

so .. get the number as a factor of 10 first .. and see to which group it belongs (using ifs.. etc)

Need to store:
I,II,III..... IX
and
X,L,C,D,M

Last edited by a moderator: May 4, 2017