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

AI Thread Summary
The discussion centers around a C++ program designed to convert integers into Roman numerals for values between 1 and 9. The code includes conditional statements to print "IX" for 9, "V" for values between 5 and 8, "IV" for 4, and "I" for values between 1 and 3. There is a suggestion that using a list of if-statements for larger numbers, such as up to 10,000, would lead to a lengthy program. Participants emphasize the importance of expanding the logic to accommodate larger digits, tens, and hundreds, indicating that the current implementation is a good start but requires further development for broader functionality.
mulabisc
Messages
3
Reaction score
0
#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
If you're going to make a list of if-statements and you need to accept numbers up to 10,000 it's going to be a long program.
 
i wil try it n post it...thanks for the advice
 
Code:
else if(n >=1 && n <=3)

cout << "I";
This will print a I for numbers 1 to 3. You may want to check on it.

You are on the right track for 1 to 9.

Keep it up for other digits, tens, hundreds, etc.
 
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