我编写了以下代码,我似乎不知道为什么它会这样做,你能帮助我,简单的用户输入1到100之间的等级的代码请求,如果用户输入的值大于100,代码提示用户再次尝试,奇怪的行为是当用户在第二次进入时,他再次输入大于100的值,代码将结果评为A级,为什么会这样做:
#include <stdio.h>
int get_grade(void){
int grade;
scanf ("%3d",&grade);
return grade;
}
int main (){
int grade=0;
printf ("please Enter your Grade \n");
grade=get_grade();
switch (grade){
case 101 ... 999 :
printf ("the score is out of 100 and you entered %d, please enter new Grade :",grade);
grade=get_grade();
// we removed break to continue with next case, this step is called fall through in programming
case 80 ... 100:
printf ("your grade is A %d\n",grade);
break;
case 60 ... 79:
printf("your grade is B \n");
break;
case 50 ... 59:
printf ("your grade is C \n");
break;
default:
printf ("we consider you failed \n");
}
return 0;
}
答案 0 :(得分:1)
由于您发布的代码中的注释指定,因此在切换块中从第一种情况到第二种情况都会出现下降。因此,在第二次调用l1 <- l %>% mutate(m2 = match(sapply(strsplit(l$pheno, "[.]"),
function(x) x[1]), reorderLevels)) %>%
arrange(m2) %>%
select(-m2)
之后,代码将进入第二种情况。