----------------解决方案--------------------------------------------------------
谢谢各位
----------------解决方案--------------------------------------------------------
#include <stdio.h>
#include <conio.h>
int main(void)
{
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;
}
//不过我不知道你在干什么!
//换句话说,我不知道你的程序干什么!
----------------解决方案--------------------------------------------------------
count
----------------解决方案--------------------------------------------------------
把average= total / counter;放在if语句外边,if(average!=0)
这样应该就可以了,
我是新手,说错了别见怪。
----------------解决方案--------------------------------------------------------
count初始化的时候定义为1,默认肯定会输入一个-1的,因此count只能大于等于1而不可能小于1,所以这个时候是if (counter != 0){
average=( float ) total / counter;
printf("class average is %.2f\n",average);
}
else {
printf("cuowu\n");
}
进步去else的
----------------解决方案--------------------------------------------------------