VB icon

Convert_Roman_Nos.

Email
Submitted on: 1/1/2015 2:45:00 PM
By: Anirudh Wadhwa (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 884
 
     THIS IS THE "FASTEST" ALGORITHM FOR CONVERSION OF ROMAN NUMERALS INTO NUMBERS.IT WILL CONVERT ALL ROMAN NUMERALS INTO NUMBERS IN RECORD TIME.IF ANY ONE KNOWS ANY FASTER METHOD PLEASE LET ME KNOW.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Convert_Roman_Nos.
// Description:THIS IS THE "FASTEST" ALGORITHM FOR CONVERSION OF ROMAN NUMERALS INTO NUMBERS.IT WILL CONVERT ALL ROMAN NUMERALS INTO NUMBERS IN RECORD TIME.IF ANY ONE KNOWS ANY FASTER METHOD PLEASE LET ME KNOW.
// By: Anirudh Wadhwa (from psc cd)
//
// Assumes:THIS PROGRAM WILL CONVERT ROMAN NUMERALS INTO NUMBERS REGARDLESS OF THEIR CASE.XXIV = xxiv = 24
//**************************************

#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
//For Any Queries,MailMe themask99@yahoo.com 
void main()
{
char a[15];
cout<<"Enter The Roman Number :"; 	
cin>>a;
for(int x=0,p=0,flag=0,rom=0,int i=strlen(a)-1;i>=0;i--)
	{
	if (a[i]=='i' || a[i]=='I') x=1; 
if (a[i]=='v' || a[i]=='V') x=5; 
	if (a[i]=='x' || a[i]=='X') x=10; 
	if (a[i]=='l' || a[i]=='L') x=50; 
	if (a[i]=='c' || a[i]=='C') x=100; 
	if (a[i]=='d' || a[i]=='D') x=500;
	if (a[i]=='m' || a[i]=='M') x=1000; 
 	
	if (x<p) flag = -1; 
	else flag = 1;
 
	rom= rom + (x*flag);
	p=x;	//storing the previous value in x
	}
cout<<"Numerical value is : "<<rom;
getch();
}


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


 There are no comments on this submission.
 

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.