Please give me the logic or a simple program to convert a Roman letter to Numeral . Please.......

Ok this is really simplistic code, I have just started learning programming but its a good start to convert roman to numbers. Plus its helping me understand C++ more, & as you can see I have just learnt switch structures :P But you can only convert a roman numeral that is one letter.

On a side note, does anyone know how I could change this code to read roman numerals of more than one character and return the number? Also is there a better way of doing this instead of switch structures?

#include <iostream>
#include <string>

using namespace std;


int main()
{
	char n = 'a';
	int nn;
	cout << "Please enter a Roman numeral: ";
	cin >> n;
	cout << "Roman numeral= " << n << endl;

	switch (n)
	{

	case 'm':
	case 'M':
		nn = 1000;
		cout << "Number= " << nn;
		break;
	case 'l':
	case 'L':
		nn = 100;
		cout << "Number= " << nn;
		break;
	case 'x':
	case 'X':
		nn = 10;
		cout << "Number= " << nn;
		break;
	case 'v':
	case 'V':
		nn = 5;
		cout << "Number= " << nn;
		break;
	case 'i':
	case 'I':
		nn = 1;
		cout << "Number= " << nn;
		break;
	default:
		cout << "This is not a Roman Numeral!";
	}

	return  0;
}

I would use a map from STL. Actually, map is a better data structure to be used in this case.
To the OP:
It is still not clear if you want to convert a Roman letter (like 'V' 'I' 'L' 'M') or a whole roman number( like 'IV' 'VII' ). The former is trivial but latter may require some skills.

This article has been dead for over six months. Start a new discussion instead.