You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
2.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <stdio.h>
struct Student
{
char cSchool[15];
char cGrade[15];
char cName[15];
};
int test();
int checknum(int a,int b);
int checkresult(int x); /*函数说明*/
int a=-1,b,c,x;
int k=0,grade; /*定义所需要的参数*/
int main()
{
struct Student student1;
printf("****预祝测试顺利****\n\n");
printf("学校:");
scanf("%s",&student1.cSchool);
printf("年级:");
scanf("%s",&student1.cGrade);
printf("姓名:");
scanf("%s",&student1.cName);
printf("\n");
printf("请回答下面十道题目\n");
do{
int i=test();
if(i==-1)
{
if(grade>=90)
printf("-------SMART");
else if(grade>=80&&grade<90)
printf("-------GOOD");
else if(grade>=70&&grade<80)
printf("-------OK");
else if(grade>=60&&grade<70)
printf("-------PASS");
else
printf("-------TRY AGAIN");
break;
}
else if(checkresult(i)==0){
a=-1;
}
}while(k);
return 0;
}
int test()
{
srand((unsigned int)time(NULL));
while(checknum(a,b)==0) /*若返回0则重新取值若返回1则完成a,b取值*/
{
a=rand()%51; /*a取值范围0~50*/
b=rand()%51; /*b取值范围0~50*/
c=rand()%2; /*c取值范围0~1*/
}
k++; /*k表示第几题*/
if(k==11)
{
printf("\n所有题目已答完,你的成绩:%d分",grade);
return -1;
}
else if(c==0)
{
printf("第%d题:%d+%d=",k,a,b);
return a+b;
}
else if(c==1)
{
printf("第%d题:%d-%d=",k,a,b);
return a-b;
}
return -1;
}
int checknum(int a,int b) /*检查相加或相减的两个数是否满足要求*/
{
if(a>50||b>50||a<0||b<0||(a+b)>50||(a-b)<0)
return 0;
else
return 1;
}
int checkresult(int result)
{
int i;
for(i=1;i<4;i++)
{
scanf("%d", &x);
if (x!=result)
{
if (i==3)
{
if (c==0){
printf("三次回答错误,正确答案是%d\n",a+b);
}
else {
printf("三次回答错误,正确答案是%d\n",a-b);
}
return 0;
}
printf("回答错误,请再次输入:");
}
else{
switch(i){
case 1:grade+=10;
break;
case 2:grade+=7;
break;
case 3:grade+=5;
break;
default:grade+=0;
break;
}
return 0;
}
}
return 0;
}