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

  • Context: C/C++ 
  • Thread starter Thread starter mulabisc
  • Start date Start date
  • Tags Tags
    C++ Numbers Program
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
mulabisc
Messages
3
Reaction score
0
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;

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

if(n == 9)

count << "IX";

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

count << "V";

else if (n == 4)

count << "IV";


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

count << "I";




return 0;
}
 
Physics news on Phys.org
http://maryt.files.wordpress.com/2007/03/roman_numerals_complete.jpg

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: