小编use*_*243的帖子

循环在第一次之后跳过scanf语句

这是main()的代码:

int main (void)
{
float acres[20];
float bushels[20];
float cost = 0;
float pricePerBushel = 0;
float totalAcres = 0;
char choice;
int counter = 0;

for(counter = 0; counter < 20; counter++)
{   
    printf("would you like to enter another farm? "); 

    scanf("%c", &choice);

    if (choice == 'n')
    {
        printf("in break ");
        break;
    }

    printf("enter the number of acres: ");
    scanf("%f", &acres[counter]);

    printf("enter the number of bushels: ");
    scanf("%f", &bushels[counter]);

}


return 0;
}
Run Code Online (Sandbox Code Playgroud)

每次程序运行第一次scanf工作正常,但在第二次通过循环时,scanf输入一个字符不会运行.

c loops for-loop scanf

3
推荐指数
1
解决办法
5092
查看次数

标签 统计

c ×1

for-loop ×1

loops ×1

scanf ×1