我看了六个钟头代码就是看不出错误!运行出错.高手帮忙解答!
int main(){
int counter;
int grade;
int total;
float average;
total=0;
counter=1;
printf ("enter grade, -1 to end:");
scanf ("%d",&grade);
while ( grade != -1){
total=total+grade;
counter=counter+1;
printf ("enter grade, -1 to end:");
scanf("%d",&grade);
}
if (counter != 0){
average=( float ) total / counter;
printf("class average is %.2f\n",average);
}
else {
printf("cuowu\n");
}
getch();
return 0;
}
问题出在比如你输入 -1 然后回车 居然不会显示 "cuowu" 请教