Extracting Characters from String

Hi All,

I’m in the process of building a C++ program that prompts the user for two Roman numerals, then prompts the user for an arithmetic operator, then calculates the two Roman numerals.

-----------------------------------------------------

For example:

-----------------

Enter first Roman numeral:

// user enters XV, which is 15.

Enter second Roman numeral:

// user enters XX, which is 20.

Enter arithmetic operator:

// user enter +

Your answer is: XXXV // which is 35.

----------------------

For simplicity purposes I’m listing Roman numerals by highest value to lowest value. Therefore the number four will be represented in the program as IIII, not IV.

Now, to the problem. After the user enters a Roman numeral I need the program to convert the Roman numeral to a float value in order to perform the calculation; this is what I cannot do. The following is what I’m trying to do in a void function:

--------------------------------------------------------------------------

void GetRoman()

{

string firstRoman;

//string secondRoman;

//char math;

//int RomanI = 1;

//int RomanV = 5;

//int RomanX = 10;

//int RomanL = 50;

//int RomanC = 100;

//int RomanD = 500;

//int RomanM = 1000;

int loopCount;

int loop = 0;

char ch;

cout << " Enter first Roman numeral: ";

cin >> firstRoman;

loopCount = firstRoman.length();

while (loop < loopCount)

{

loop = loop++;

getline(cin, firstRoman);

cin.get();

--------------------------------------------------------------------------

What I would like to do is start a loop, get the first character of the string “firstRoman”, read it, then convert it to a float value as listed by the above variables, some of which are commented out.

Any help would be appreciated.

Thanks,

bob2509