Important alert: (current site time 10/25/2014 7:32:15 AM EDT)
 

VB icon

Arabic to Roman numerals Convertor

Email
Submitted on: 9/21/2007 11:20:49 AM
By: zkey  
Level: Intermediate
User Rating: By 2 Users
Compatibility: C++ (general)
Views: 14714
 
     This program converts arabic numerals into roman numerals. That's all folks! :)
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :Arabic to Roman numerals Convertor
//**************************************
#include <iostream>
#include <conio.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Arabic to Roman numerals Convertor
// Description:This program converts arabic numerals into roman numerals. That's all folks! :)
// By: zkey
//
// Inputs:number (int) < 4000
//
// Returns:roman number
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=4571&lngWId=3//for details.//**************************************

// !date written: ?.03.2001
// !date published: 15.08.2002
// !page@home: http://www.zkey.de
using namespace std;
// roman_all[0] : contains x, where x % 100 = 0
// roman_all[1] : contains x, where x % 10 = 0
// roman_all[2] : contains x, where x less then 10
const char ROMAN_ALL[3][3] = {{'C','D','M'}, {'X','L','C'}, {'I','V','X'}};
void print_roman(int num, int which);
int main()
{
int k=0;
int num=0;
int array_num[4] = {0};
do
{
cout << "-- (c) 2001 zkey, http://www.zkey.de --\n";
cout << "-- Convert arabic to roman numbers--\n";
cout << "---------------------------------------\n";
cout << "Insert arabic number < 4000: ";
cin >> num;
if (num >= 4000)
cout << "Please input a number < 4000 ...\n";
}
while (num >= 4000);
for (int i=0; num>=1; i++)
{
array_num[i] = num%10;
num/=10;
}
cout << "Roman number: ";
do
{
if (array_num[3-k])
print_roman(array_num[3-k], k);
k++;
}
while (k<4);
_getch();
return 0;
}
void print_roman(int num, int which)
{
int i;
if (which--)
{
switch (num)
{
case 1:
case 2:
case 3:
for (i=0; i<num; i++) cout << ROMAN_ALL[which][0];
break;
case 4:
cout << ROMAN_ALL[which][0] << ROMAN_ALL[which][1];
break;
case 5:
cout << ROMAN_ALL[which][1];
break;
case 6:
case 7:
case 8:
cout << ROMAN_ALL[which][1];
for (i=0; i<(num-5); i++) cout << ROMAN_ALL[which][0];
break;
case 9:
cout << ROMAN_ALL[which][0];
cout << ROMAN_ALL[which][2];
break;
}
}
else
for (i=0; i<num; i++) cout << ROMAN_ALL[0][2];
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/15/2004 11:51:18 PM

How would you convert this program to go the oppisite way, from Roman to decimal?

thanks
(If this comment was disrespectful, please report it.)

 
3/31/2006 12:03:10 AMsachin

Good Programming
(If this comment was disrespectful, please report it.)

 
6/7/2012 1:45:42 AM

2012 and still good ..
tnx a lot
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.