我在Visual Studio 2015上进行编码。当我在C程序下面执行时,在执行程序中跳过 else part&#39的字符scanf函数并显示&#34 ;您输入了无效字符。" 直接输入。有什么问题?
double grade1, grade2, avarage;
char yes_no; //character variable for (Y/N) statement
int std; //index for students
int std_num; //number of students
printf("Enter how many students will be determined: ");
scanf("%d", &std_num);
for (std = 1; std <= std_num; std++); //loop statement
{//curly brace for loop
printf("Enter two grades: "); //display for inputs
scanf("%lf %lf", &grade1, &grade2); //input statement
avarage = (grade1 + grade2) / 2;
if (avarage >= 50)
printf("Successful.\n");
else
{
printf("Did the student take this exam before?(Y/N): ");
scanf("%c", &yes_no);
if (yes_no == 'Y' || yes_no == 'y')
printf("Unsuccessful, and has no other chance.\n");
else if (yes_no == 'N' || yes_no == 'n')
printf("Unsuccessful, but has one more chance.\n");
else
printf("You entered an invalid character.\n");
}
}//curly brace for end of the loop
return 0;
}