Roman Numerals

I'm writing a program that changes a new roman numeral input into base10.
It must take multiple inputs and use a switch statement. It does not seem to
make it to the switch.

#include <iostream>
//Jacob Wilt
//Roman Numerals
using namespace std;

char roman;
int total = 0;

int main()
{
cout << "Input a Roman Numeral (Capitalized)." << endl;
cin >> (roman);
while (roman != ' ')
{
switch (roman)
{
case 'M':
{
total = total + 1000;
break;
}
case 'D':
{
total = total + 500;
break;
}
case 'C':
{
total = total + 100;
break;
}
case 'L':
{
total = total + 50;
break;
}
case 'X':
{
total = total + 10;
break;
}
case 'V':
{
total = total + 5;
break;
}
case 'I':
{
total = total + 1;
break;
}
default:
{
cout << "ERROR!!!" << endl;
break;
}
cout << total << endl;
cout << "Input a Roman Numeral (Capitalized)." << endl;
cin >> roman;
}
}
return 0;
}
First of all, use code tags, to make your program easier to read, and to comment (I cannot easily point out your line numbers where I have questions)
1. Don't use global variables (bad habit)
2. Do you rally want to work with only one character? If not roman should be a char array, or a vector of char
3. It is very difficult to see without proper formatting, but say you select 'M', then break will send you out of the switch, right after your second cin >> roman;. The three commands after default are never going to be executed. It would help if you move the closing curly bracket from after cin >> roman; to before cout << total << endl;
4. Brush up on your roman numerals. If I input 'X' then 'L', you would translate it as 60, instead of 40

how do you use code tags? and I can't use arrays yet.
http://www.cplusplus.com/forum/articles/42672/
Hard if you cannot use arrays. MCMXCIX is 1999. You should have something like this in the end http://stackoverflow.com/questions/17724887/c-converting-roman-numerals-to-decimals
Topic archived. No new replies allowed.