我希望用户选择何时完成输入,以便初始化"完成"。但循环绕过了那个。 我尝试过,做while while循环,但它并没有为我做
char snails[8][11];
int count;
int finish;
do
{
for (count = 0; count < 8; count++)
{
printf("Enter the snail's name:");
scanf("%10s", &snails[count]);
int timea;
int timeb;
int timec;
int timed;
printf("Enter %s 's time for the first leg:", snails[count]);
scanf("%d", &timea);
printf("Enter %s 's time for the second leg:", snails[count]);
scanf("%d", &timeb);
printf("Enter %s 's time for the third leg:", snails[count]);
scanf("%d", &timec);
printf("Enter %s 's time for the fourth leg:", snails[count]);
scanf("%d", &timed);
int timef = timea + timeb + timec + timed;
int time1 = timef / 60;
int time2 = timef % 60;
printf("%s finished in %d minutes and %d seconds \n", snails[count], time1, time2);
printf("Type 1 if you have finished inputting or 0 if you have not:");
scanf("%d", &finish);
}
} while (finish == 0);
return 0;
}
答案 0 :(得分:0)
如果您打算最多执行8次循环,除非它们表明它们已完成:
1.删除do while循环。
2.执行以下操作之一: 将外观的条件更改为:
count < 8 && finish != 1
或从for循环中断:
if (finish == 1) break;
然后它将执行for循环,直到: