Can someone help me about converting numbers to roman numeral 1-999 via switch statement ?

please help me !

Recommended Answers

All 7 Replies

This is posed in the wrong forum. You would need to post this in the C++ forum to get responces.

My responce anways:

Can someone help me about converting numbers to roman numeral 1-999 via switch statement ?

Yes, I can help. I can even write the entire thing for you. I'm not going too, but the answer to the question is still "yes".

If you want to get this done, then show us what you've tried, or which part you're stuck on.

I really doing this manually up to 999 , I want to get the shortcut of this one !

#include <iostream.h>
#include <conio.h>
main()
{
 clrscr();
 int n,a,b;

 cout<<"Enter a Number\n";
 cin>>a;
 switch(a)
 {case 1:
 cout<<"I";
 break;
 case 2:
 cout<<"II";
 break;
 case 3:
 cout<<"III";
 break;
 case 4:
 cout<<"IV";
 break;
 case 5:
 cout<<"V";
 break;
 case 6:
 cout<<"VI";
 break;
 case 7:
 cout<<"VII";
 break;
 case 8:
 cout<<"VIII";
 break;
 case 9:
 cout<<"IX";
 break;
 case 10:
 cout<<"X";
 break;
 }
 switch(a)
 {case 11:
 cout<<"XI";
 break;
 case 12:
 cout<<"XII";
 break;
 case 13:
 cout<<"XIII";
 break;
 case 14:
 cout<<"XIV";
 break;
 case 15:
 cout<<"XV";
 break;
 case 16:
 cout<<"XVI";
 break;
 case 17:
 cout<<"XVII";
 break;
 case 18:
 cout<<"XVIII";
 break;
 case 19:
 cout<<"XIX";
 break;
 case 20:
 cout<<"XX";
 break;}

 switch(a)
 {case 21:
 cout<<"XXI";
 break;
 case 22:
 cout<<"XXII";
 break;
 case 23:
 cout<<"XXIII";
 break;
 case 24:
 cout<<"XXIV";
 break;
 case 25:
 cout<<"XXV";
 break;
 case 26:
 cout<<"XXVI";
 break;
 case 27:
 cout<<"XXVII";
 break;
 case 28:
 cout<<"XXVIII";
 break;
 case 29:
 cout<<"XXIX";
 break;
 case 30:
 cout<<"XXX";
 break;
 }
 switch(a)
 {case 31:
 cout<<"XI";
 break;
 case 32:
 cout<<"XII";
 break;
 case 33:
 cout<<"XIII";
 break;
 case 34:
 cout<<"XIV";
 break;
 case 35:
 cout<<"XV";
 break;
 case 36:
 cout<<"XVI";
 break;
 case 37:
 cout<<"XVII";
 break;
 case 38:
 cout<<"XVIII";
 break;
 case 39:
 cout<<"XIX";
 break;
 case 40:
 cout<<"XX";
 break;}


 getch();
 return 0;
 }

why don't you try to come up with an algorithm to compose Roman numerals from Arabic numerals?
It's not that hard...

And oh, don't use Turbo C++, it's 30 years old by now, not supported on any operating system from the last 20 years or so.
It's a dinosaur, nice to have for collectors of curiosa, not for people interested in writing modern C++ (which it won't support, its syntax and command set are archaic).

But it's the only program that i could use because my teacher said it !

I see. That's an unfortunately common problem, and frankly, the best solution is to walk out of the course, making sure the instructor knows why you are getting out. You aren't going to learn anything useful in it if the professor insists on using obsolete technology. However, it is disgusting common for IT departments (and in the cases of India and Pakistan, entire national university systems) to standardize on that particular antique software, so you may not have to option.

There is a pattern here. Just try to break it down before you start coding.

Notice what happens when the last digit is 1, 2, 3, 6, 7, 8. Notice what happens when the last digit is 0, 4 ,5, 9.

Notice how the next more signifigant digit changes as the numbers get higher.

so you're willing to spend a lot of time and money to learn to use something that the world has long since stopped using?
And what then, are you going to lie through your teeth claiming to know modern C++ when in fact you don't?

Yes, walk out of that course and demand your money back, and make sure they know why. You're being robbed of a decent education.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.