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

AI Thread Summary
The discussion focuses on improving a C++ program designed to convert integers from 1 to 1000 into Roman numerals. The initial code provided only handles specific cases, such as 1 to 9, and lacks a comprehensive approach for larger numbers. Key points include the need to implement logic for numbers in groups of tens and hundreds, utilizing the Roman numeral system's structure. Participants suggest establishing a method to categorize numbers based on their value, using conditional statements to determine the appropriate Roman numeral representation. Additionally, there is an emphasis on storing numeral components like I, V, X, L, C, D, and M for efficient conversion. The discussion also references a visual guide for Roman numeral values, highlighting the importance of understanding the numeral system's rules for accurate conversion.
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;

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;
}
 
Technology 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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
22
Views
3K
Replies
5
Views
3K
Replies
39
Views
4K
Replies
1
Views
1K
Replies
8
Views
2K
Replies
40
Views
3K
Back
Top