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.

93 lines
1.6 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"
#include"stdlib.h" //随机函数头文件//
#include"time.h" //时间函数头文件//
int add(int j,int x, int y); //加法计算//
void sub(int j,int x, int y); //减法计算//
int sum=0; //记录得分//
int pd(int result) //*判断输入是否正确 正确 返回1 错误 返回-1*//
{ int n;
scanf("%d",&n);
if(result==n)
return 1;
return -1;
}
void jifen(int result) //根据错误次数记分累加到sum//
{
if(pd(result)==1)
sum+=10;
else
{
printf("\n答案错误请重新输入:"); //错一题 //
if(pd(result)==1)
sum+=7;
else
{
printf("\n答案错误请重新输入:"); //错两题//
if(pd(result)==1)
sum+=5;
else
printf("\n答错三次请继续解答下一题:\n"); //错三题//
}
}
}
int main()
{
int i,x,y,ch,z;
srand(time(NULL));//随机函数 产生不同的随机数//
printf("小学生计算题\n");
for(i=0;i<10;i++)
{
x=rand()%51;
y=rand()%51;
ch=rand()%2;
switch(ch)
{
case 0: z=add(i+1,x,y);
if(z==1) //重新出一题//
i=i-1;
break;
case 1: sub(i+1,x,y);
break;
default:
printf("系统出错");
break;
}
}
printf("你的分数为:%d ",sum);
if(sum>=90&&sum<=100)
printf("SMART");
else if(sum>=80)
printf("GOOD");
else if(sum>=70)
printf("OK");
else if(sum>=60)
printf("PASS");
else if(sum>=0)
printf("TRY AGAIN");
else
printf("系统错误");
return 0;
}
int add(int j,int x,int y)
{
int result;
result=x+y;
if(result>50) //判断是否超出范围 超出返回1//
return 1;
printf("%d:%d+%d=",j,x,y);
jifen(result);
return -1;
}
void sub(int j,int x,int y)
{
int result,t;
if(x<y) //保证差大于0//
{
t=x; x=y ; y=t;
}
result=x-y;
printf("%d:%d-%d=",j,x,y);
jifen(result);
}