The rest of the part which includes string like 'IV' are yet to be done, but right now the problem is for 'I' the program is returning 8 instead of 1;
#include <bits/stdc++.h> //header file
using namespace std;
int romantoint(char str[],int &n)
{
int total=0;
unordered_map <char,int> m;
m['I'] = 1;
m['II'] = 2;
m['III'] = 3;
m['IV'] = 4;
m['V'] = 5;
m['VI'] = 6;
m['VII'] = 7;
m['VIII'] = 8;
m['IX'] = 9;
m['X'] = 10;
for(int i=0;i<n;i++)
{
total = total+m[str[i]];
}
return total;
}
int main()
{
char str[] = "I";
int n = strlen(str);
cout<<romantoint(str,n);
}