我试图做到这一点 - 当用户按y再次询问时重复,但由于某种原因,它第二次通过低谷(但显示)第一个问题,它直接转到最后一个问题所以它结束。我在这里做错了什么?
#include <stdio.h>
#include <stdlib.h>
int main()
{
char op;
char ans;
int count_y, count_n;
count_y=0;
count_n=0;
do{
fflush(stdin);
printf("\n Do you have a pc ?");
scanf("%c", &op);
fflush(stdin);
if(op == 'y'){
count_y++;
}else{
count_n++;
}
printf("\n ask again? y/n: ");
scanf("%c", &ans);
}while(ans == 'y');
printf("total y: %d, total n %d.", count_y, count_n);
system( "read -n 1 -s -p \"Press any key to continue...\"" );
return 0;
}