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.

70 lines
1.2 KiB

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int num=0,add=0; /* 答题数,总分 */
int score[3]={10,7,5};/*得几分*/
char str[20],str1[10][20];
while(1)
{
int a=0,b=0,d=0,c=0,k=0,i=0,j=-1,result;
char sf[2]={'+','-'};/* 符号 */
while(1)
{
a=rand()%51;/*0-50的随机数*/
b=rand()%51;/*0-50的随机数*/
d=rand()%2;/* 随机符号 */
if(d==0)c=a+b;
else c=a-b;
if(c>=0 && c<=50)/* 如果相同重新出题 */
{
sprintf(str,"%d %c %d = \n",a,sf[d],b);
strcpy(str1[num],str);
if(num==0) break;
j=-1;
for(i=0; i<num; i++)
{
if(strcmp(str,str1[i])==0)
{ j=1;break;}
}
if(j<0)
break;
}
}
printf("%s\n",str);/* 回答 */
printf("输入计算结果:\n");
while(1)
{
scanf("%d",&result);
k++;
if(result==c)
{
printf("回答正确!\n");
add+=score[k-1];
break;
}
else if(k<3)
{
printf("错误,请重新回答:\n");
}
else
{ printf("错误,正确答案: %d\n",c);
break;
}
}
num++;
if(num==10)break;
}
if(add>=90)printf("\nSMART\n");
else if(add>=80)printf("\nGOOD\n");
else if(add>=70)printf("\nOK\n");
else if(add>=60)printf("\nPASS\n");
else printf("\nTRY AGAIN\n");
getch();
}