答题类游戏要求用c语言编写
发布网友
发布时间:2022-06-11 06:02
我来回答
共2个回答
热心网友
时间:2024-12-13 05:59
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(int argc, char const* argv[])
{
int a, b, c, ch, all, calc, number;
a = b = c = ch = all = calc = number = 0;
while(1)
{
srand((unsigned)time(NULL));
number = rand();
a = number%100;
b = number%101;
ch = number%4;
switch(ch)
{
case 0:
printf("%d+%d=?\n", a, b);
scanf("%d", &c);
all++;
if(a+b==c)
calc++;
break;
case 1:
printf("%d-%d=?\n", a, b);
scanf("%d", &c);
all++;
if(a-b==c)
calc++;
break;
case 2:
printf("%dX%d=?\n", a, b);
scanf("%d", &c);
all++;
if(a*b==c)
calc++;
break;
case 3:
printf("%d/%d=?\n", a, b);
scanf("%d", &c);
all++;
if(a/b==c)
calc++;
break;
default:
printf("程序异常\n");
break;
}
if(all==9)
break;
}
printf("本次测试你得分是%d\n", (calc+1)*10);
return 0;
}
热心网友
时间:2024-12-13 06:00
哪个地方不会写?