我有一个代码将罗马数字转换为二进制数字,我必须做到这一点,以便用户可以选择让程序读取.txt文件中的罗马数字或输入自己的数字 . 我有转换器代码,但我无法从文件读取,也不知道如何让用户在2个选项之间进行选择 . 我将永远感谢你的帮助 .
char Roman[100];
int counter=0;
int arabic =0;
printf("Input the roman number you want to convert \n");
scanf("%s",Roman);
while(Roman[counter]){
if(numerals(Roman[counter]) < 0)
{
printf("Roman numeral does not exist: %c",Roman[counter]);
return 0;
}
if((strlen(Roman) -counter) > 2)
{
if(numerals(Roman[counter]) < numerals(Roman[counter+2]))
{
printf("Incorrect roman number entered");
return 0;
}
}
if(numerals(Roman[counter]) >= numerals(Roman[counter+1]))
arabic= arabic + numerals(Roman[counter]);
else
{
arabic= arabic + (numerals(Roman[counter+1]) - numerals(Roman[counter]));
counter++;
}
counter++;
}
printf("The arabic value of the roman number is : %ld",arabic);
return 0;