当我尝试移动我的 Do 循环或添加另一个循环来嵌套它时,我遇到了一个奇怪的问题。我将 DO 放在您在下面看到的地方,它可以很好地循环:
{
float numbers[MAX_DATA];
printf("Please Eneter the Amount of Numbers You Would Like to Use\n");
scanf("%d",&amount);
if (amount>MAX_DATA)
{
printf("Your entry was too big");
}
else
{
input(numbers,amount);
do
{
printf("\nStatistical Calculator Menu\n");
printf("\n(1) Mean\n(2) Standard Deviation\n(3) Range\n(4) Restart/Exit\n");
scanf("%d",&input2);
if (input2==1)
{
mean(numbers,amount);
}
else if (input2==2)
{
standard(numbers,amount);
}
else if (input2==3)
{
range(numbers,amount);
}
else if(input2==4)
{
printf("Would You Like to (5)Restart or (6)Quit?");
scanf("%d",&input2);
}
}
while(input2!=4);
}
getch();
return 0;
}
但是如果我把它放在这里或者添加一个额外的 do 循环来嵌套它,我会得到一个“expect while before getch”错误。
{
int amount=0;
int input2;
do
{
float numbers[MAX_DATA];
printf("Please Eneter the Amount of Numbers You Would Like to Use\n");
scanf("%d",&amount);
if (amount>MAX_DATA)
{
printf("Your entry was too big");
}
else
{
input(numbers,amount);
printf("\nStatistical Calculator Menu\n");
printf("\n(1) Mean\n(2) Standard Deviation\n(3) Range\n(4) Restart/Exit\n");
scanf("%d",&input2);
if (input2==1)
{
mean(numbers,amount);
}
else if (input2==2)
{
standard(numbers,amount);
}
else if (input2==3)
{
range(numbers,amount);
}
else if(input2==4)
{
printf("Would You Like to (5)Restart or (6)Quit?");
scanf("%d",&input2);
}
}
while(input2!=4);
}
getch();
return 0;
}
为什么我会收到此错误?