I need to make a program that converts Roman numerals to its decimal numbers. I need to include a function that yields the numeric value of each of the letters, and another function that converts the Roman number string and returns its value as follows: Look at the first two characters of the string. If the first has a larger value than the second, then simply convert the first, call the conversion function again for the substring starting with the second character, and add both values. If the first one has a smaller value than the second, compute the difference and add it to the conversion of the substring starting at the third character.
This is what I did so far, and I don't know if I am doing it right, and what I should do, to successfully make the program.
#include<iomanip>
#include<iostream>
#include<string>
usingnamespace std;
void RomanInitialize();
void RomanInitialize(){
int M = 1000;
int D = 500;
int C = 100;
int L = 50;
int X = 10;
int V = 5;
int I = 1;
}
int main(){
cout << " Enter the Roman Numeral Value: ";
string roman;
cin >> roman;
string sub = roman.substr(0, 2);
cout << sub << endl;
string Num = sub.substr(0, 1);
string Numeral = sub.substr(1, 2);
if (Num > Numeral){
if (Num == "M"){
RomanInitialize();
int M = 1000;
int D = 500;
int C = 100;
int L = 50;
int X = 10;
int V = 5;
int I = 1;
cout << static_cast<int>(Num + Numeral) << endl;
}
elseif (Numeral > Num){
cout << "values " << Numeral + Num << endl;
}
}
}