Question: The program is supposed to convert roman numbers to digits. The problem in my code is that when the user starts with (XC, CM, or

The program is supposed to convert roman numbers to digits. The problem in my code is that when the user starts with (XC, CM, or MU) the loop breaks and won't read the rest of the input. for example (XCV should print 98) but it only reads reads XC (90). I tried to use "continue" but it didn't work. Please explain what have I done wrong
#include
int main() { char roman[20]; int result = 0; printf("Enter a roman numeral:\t"); scanf("%s", roman); int length = 0; int i = 0; while(roman[i]!='\0') { roman[i]=toupper(roman[i]); i++; }
length = i; printf("%d ",length);
for(i=0;i else if(roman[i+1]=='\0'|| (roman[i+1]=='I'))//one ,two or three { result+=1; } else if(roman[i+1]=='V') { result+=4; break; } else if(roman[i+1]=='X') { result+=9;break; } else { printf("Error I2"); break; } } else if(roman[i]=='V') { if( i+4 } else { printf("Error V2"); break; } } else if(roman[i]=='X') { if(roman[i+1]=='\0'||roman[i+1]=='X'|| roman[i+1]=='V'|| roman[i+1]=='I') { result+=10; } else if(roman[i+1]=='L') { result+=40; } else if(roman[i+1]=='C') { result+=90; break; } else { printf("Error X"); break; } } else if(roman[i]=='L') { if(i+16 else { printf("Error L2");//fix me break; } } else if(roman[i]=='C') { if(i+11 else { printf("Error C2");//fix me break; } } else if(roman[i]=='D') { if(i+12 } else if(roman[i]=='M') { if(i+16 } //end of the last if statement -------------------------------------------- else { printf("Error"); break; } }// end of the loop if(result!=0) printf("%d",result); return 0; }// end of the code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
