Important alert: (current site time 10/21/2014 10:50:05 PM EDT)
 

VB icon

Roman Numeral to Decimal Number Converter

Email
Submitted on: 11/11/2007 9:32:33 AM
By: Jacob Landis 
Level: Beginner
User Rating: Unrated
Compatibility: C++ (general)
Views: 4373
 
     This program prompts the user to enter a Roman Numeral and the converts that Roman Numeral to a Decimal Number. The program only handles Roman Numerals up to M (1000) and if a user enters, for example, IV or VI they will get 6. This program is a good starting point and can easily be built upon.
 
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: Roman Numeral to Decimal Number Converter
// Description:This program prompts the user to enter a Roman Numeral and the converts that Roman Numeral to a Decimal Number. The program only handles Roman Numerals up to M (1000) and if a user enters, for example, IV or VI they will get 6. This program is a good starting point and can easily be built upon.
// By: Jacob Landis
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=11794&lngWId=3//for details.//**************************************

#include <iostream>
#include <cmath>
using namespace std;
void main()
{
 int roman_numeral_output = 0;
 char roman_numeral[25]; //alows user to enter up to 25 letters and the letters they enter are stored in the array roman_numeral
 cout<<"Please enter a Roman Number and then add a period and press enter "<<endl;
 for (int a = 0; a < 25; a++) //loops through data entered, place in an array
 {
cin>>roman_numeral[a]; //user enters a roman numeral
 if (roman_numeral[a] == '.') //type a period and presses enter to get an answer
 break;
 }
 for (int position = 0; position < 25; position++) //a loop to test each array value in a case statement
{
 switch (roman_numeral[position]) //adds up all the letters entered by the user
	 {
case 'i': //each case tests for both a lower case and upper case letter, this allows the user to enter either one and the program will still work fine
case 'I':
	{
roman_numeral_output = roman_numeral_output + 1; //this is where the tally for each letter entered takes place
	break;
 }
case 'v':
case 'V':
 {
roman_numeral_output = roman_numeral_output + 5;
break;
 }
case 'x':
case 'X':
 {
roman_numeral_output = roman_numeral_output + 10;
break;
 }
case 'l':
case 'L':
 {
roman_numeral_output = roman_numeral_output + 50;
break;
 }
case 'c':
case 'C':
 {
roman_numeral_output = roman_numeral_output + 100;
break;
 }
case 'd':
case 'D':
 {
roman_numeral_output = roman_numeral_output + 500;
break;
 }
case 'm':
case 'M':
 {
roman_numeral_output = roman_numeral_output + 1000;
break;
 }
	 }
}
 cout<<roman_numeral_output<<endl; //the answer to the user data is printed onto the screen
}


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 Beginner 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

11/13/2007 12:21:57 PMJerome Scott II

IV = 4 in roman numeral you program doesn't will not get true values of all roman
(If this comment was disrespectful, please report it.)

 
11/17/2007 9:50:14 AMJacob Landis

As it says in the description about "IV or VI they will get 6." I didn't intend this program to be a good starting point to build upon. Maybe later I will add other functions to the code.
(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.