请问这个哪里出问题了?输入不定数目的成绩,输入-1时停止,在先后输入54,-1,但结果是26.5
#include <stdio.h>#include <stdlib.h>
int main(void)
{
int grade,sum = 0,i=0;
float average;
printf("Plesase input the grade,if input -1,it will stop.\n");
scanf("%d",&grade);
i=i+1;
sum = sum +grade;
while(1){
if(grade!=-1){
printf("Plesase input the grade,if input -1,it will stop.\n");
scanf("%d",&grade);
sum = sum + grade;
i = i+1;
}
else{
break;
}
}
if(i!=0){
average=(float)sum/i;
printf("The average grade is:%f\n",average);
}
else{
printf("you don't input any grade.\n");
}
}