我遇到的问题是,如果输入的无效选项的类型不是im扫描,则提示用户输入值,因为我需要程序显示消息“无效条目”并中断。
if (UserInputTri == 'A')
{
system("cls");
TriPermTotal = 0;
printf("\nYou chose to calculate perimeter.\n\nPlease enter a value for side number 1: ");
scanf("%f", &TriPerm1);
printf("Please enter a value for side number 2: ");
scanf("%f", &TriPerm2);
printf("Please enter a value for side number 3: ");
scanf("%f", &TriPerm3);
TriPermTotal = TriPerm1 + TriPerm1 + TriPerm3;
printf("\nThe total perimeter of the triangle is: %0.0f\n\n", TriPermTotal);
system("pause");
system("cls");
break;
else
{
printf("\nNot a valid option, try again!\n\n");
system("pause");
system("cls");
break;
}
如果在要求用户提供第1面时输入单词而不是数字,它将永远循环。