#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int Rand()
{
int left=rand()%10+1;
int right=rand()%10+1;
int oper=rand()%2;
if(oper)
{
printf("%d+%d=",left,right);
return left+right;
}
else
{
printf("%d-%d=",left,right);
return left-right;
}
}
int main()
{
srand(time(0));
int ans,t=0,s=0;
char ch;
do
{
int result=Rand();
s++;
scanf("%d",&ans);
if(ans==result)
{
printf("恭喜!答对了.\n");
t++;
}
else printf("很遗憾,回答错误.\n");
printf("是否继续答题(Y/N):");
scanf("%c",&ch);
while(ch==32||ch==10)
scanf("%c",&ch);
}while(ch=='Y'||ch=='y');
printf("答题结束!\n您总共计算了%d次,答对%d次,得分为:%d\n",s,t,(int)((double)t*100.0/(double)s));
return 0;
}
温馨提示:答案为网友推荐,仅供参考