/*program to calculate the average of a set of grades and count the number of failing test grades */
#include <stdio.h>
main (void)
{
int grades,sum=0,grade_counter=1,failures=0,excellent=0;
float average;
char end_flag;
printf ("please enter the scores one by one!\n");
do
{
printf ("score %i: ",grade_counter);
scanf ("%i",&grades);
if (grades>=0 && grades<=100)
printf ("%i\n",grades);
sum=sum+grades;
grade_counter++;
if (grades<75)
failures++;
else
excellent++;
else if (grades<0 || grades>100)
printf ("sorry,what you've just entered exceed the right range of score,please enter a new score between 0~100!");
else
printf ("you've just entered a non-number,do you want to end entering? (Y/N)");
scanf ("%c",&end_flag);
{
if (end_flag=='y')
break;
else
printf ("please continue,just type in another data,make sure what you entered is a number between 0~100");
}
}
while (end_flag=='y');
average=(float) sum/grade_counter;
printf("The average score is: %f\n\n",average);
printf("and there are %i failures.",failures);
getch();
return 0;
}
这个程序错在哪儿了?为什么会编译失败,并一直提示红色标记处的else位置错误?
[此贴子已经被作者于2007-9-29 11:34:56编辑过]