I'm trying to write a program that converts Roman Number to integer but its compilation output the following error:
Line 65: Char 5: error: conflicting types for 'main'
int main(int argc, char *argv[]) {
^
Line 47: Char 5: note: previous definition is here
int main()
^
1 error generated.
Here there is some of my code:
class Solution {
public:
int value(char r){
if (r == 'I')
return 1;
if (r == 'V')
return 5;
if (r == 'X')
return 10;
if (r == 'L')
return 50;
if (r == 'C')
return 100;
if (r == 'D')
return 500;
if (r == 'M')
return 1000;
return -1;
}
int romanToInt(string& s) {
int ret = 0;
for (int i = 0; i < s.length(); i++) {
int s1 = value(s[i]);
if (i + 1 < s.length()) {
int s2 = value(s[i + 1]);
if (s1 >= s2) {
ret = ret + s1;
}
else {
ret = ret + s2 - s1;
i++;
}
}
else {
ret = ret + s1;
}
}
return ret;
}
};
int main()
{
Solution m;
string str = "III";
cout << "Integer form of Roman Numeral is " << m.romanToInt(str) << endl;
return 0;
}
The method value()
reads the string with the Roman Number letter by letter and recognizing the value of each letter.
I think that the main()
function needs some change in order to do this task but I am a little stuck on how to do so.