//生成随机符号
char Charop()
{
int op;
op = rand() % 4 + 1;
switch (op)
{
case 1:return '+';
case 2:return '-';
case 3:return '*';
case 4:return '/';
}
return 0;
}
//相关计算
int Calculate(int x, char op, int y)
{
int a, b, c, d;
a = x + y;
b = x - y;
c = x * y;
d = x / y;
switch (op)
{
case '+': return a;
case '-': return b;
case '*': return c;
case '/': return d;
default:return 0;
}
}
//输出运算
int fun()
{
int answer, counter = 0, grade = 0;
int x, y, m, n;
char op;
for (int i = 1;i <= 10;i++)
{
op = Charop();
srand(time(NULL));
x = rand() % 10 + 1;
y = rand() % 10 + 1;
printf("%d%c%d=", x, op, y);
scanf("%d", &answer);
if (answer == Calculate(x, op, y))
{
printf("Right!\n");
grade++;
}
else
printf("Wrong!\n");
counter++;
}
printf("grade=%d\n", grade);
printf("Scoring rate=%d%%", grade * 10);
}
//主函数
int main()
{
fun();
return 0;
}
|