#include #include #include int question( int i) { int a,b,j,m; for( i = i;i<100;i++ ) { loop: { a=rand()%51; b=rand()%51;//rand()%100表示取50以内的随机数 j=rand()%2;//j的值决定加减法 } if(j==0) { m=a+b; if(m<=50) { printf("%d+%d=\n",a,b); } else goto loop; } else { m=a-b; if(m<=50&&m>=0) { printf("%d-%d=\n",a,b); } else goto loop; } break; } return m; } int main() { int modelanswer=0; int studentanswer=0; char str[20]; int grade=0; int n; printf("\n"); printf("============================================================\n"); printf("====================50以内加减法测验系统====================\n"); printf("============================================================\n"); printf("\n"); printf("请输入你的名字:\n"); scanf("%s",str); printf("\n你好呀,%s小朋友,欢迎进入50以内加减法测验系统。\n",str); printf("每道题你有三次答题机会,如果三次机会结束则直接给出正确答案。\n"); printf("\n测试结束后会给出你的成绩以及相应评级。\n"); printf("\n"); printf("======================要注意细心哦~=========================\n\n"); for(n=1;n<11;n++) { printf("\n第%d道题:\n",n); modelanswer=question(n); printf("请输入答案:"); scanf("%d",&studentanswer); if(studentanswer==modelanswer) { printf("回答正确,请继续加油哦。\n"); grade=grade+10; } else { printf("回答错误,请好好思考。你还有两次机会。\n"); printf("请输入答案:"); scanf("%d",&studentanswer); if(studentanswer==modelanswer) { printf("回答正确,请继续加油哦。\n"); grade=grade+7; } else { printf("回答错误,请好好思考。你还有一次机会。\n"); printf("请输入答案:"); scanf("%d",&studentanswer); if(studentanswer==modelanswer) { printf("回答正确,请继续加油哦。\n"); grade=grade+5; } else { printf("回答错误。正确答案是:%d\n",modelanswer); grade=grade+0; } } } } if(grade>=90) { printf("\nSMART!\n"); } if(grade<90&&grade>=80) { printf("\nGOOD!\n"); } if(grade<80&&grade>=70) { printf("\nOK.\n"); } if(grade<70&&grade>=60) { printf("\nPASS.\n"); } if(grade<60) { printf("\nTRY AGAIN.\n"); } printf("\n你的成绩是:%d\n",grade); return 0; }