#include <stdio.h>
int main()
{
int people; //多少人數
int grade; //輸入的成績
int total; //成績的總和
float average; //成績的平均
people=0;
total=0;
printf("Enter grade ,-1 to end: ");
scanf("%d",&grade);
//迴圈如果不等於-1則繼續執行
while(grade!=-1){
total=total+grade;
people++;
printf("Enter grade ,-1 to end: ");
scanf("%d",&grade);
}
//如果人數不等於0,就開始計算平均
if(people!=0){
average = (float)total/people;
printf("Class average is %.2f\n",average);
}
else{
printf("No grades were entered\n");
}
return 0;
}