I am trying to make a program to convert from Roman numerals to base 10 numbers. I have the basic code, but the part I can't figure out is making numbers smaller if there is a smaller number in front of a larger one (example: I = 1, V = 5; I can do this but not IV which is 4). How can I do this? Here's what I have so far:Code:#include <iostream> #include <string> using namespace std; int main() { string input; int total = 0; cout << "Enter the Roman numeral: "; getline(cin, input); for (int i = 0; i < input.length(); i++) { switch(input[i]) { case 'M': total += 1000; break; case 'D': total += 500; break; case 'C': total += 100; break; case 'L': total += 50; break; case 'X': total += 10; break; case 'V': total += 5; break; case 'I': total += 1; break; } } cout << input << " equals " << total << endl; return 0; }




Reply With Quote