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

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 #include #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

Thousands Hundreds Tens Units 100 c 2000 200 CC 20 XX 3000 MMM 300 CCC 30 XXX 3 III 400 CD 500 -D 600 DC 60 1.x 700 DCC 70 LXX 7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!