该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
scanf_s,和scanf差不多,最后一个参数限定读几位。我想不通原因,同时觉得很神奇。
# include
# include
# include
//输入d.会陷入死循环,原因不明。待解。
void question(unsigned int k);
int a0;
int main(void)
{
int answer;
unsigned int kind;
srand(time(NULL));
printf("welcome to use this app to study!\nqustion: 111 to quit\n");
printf("choose the kind of operation that you'd like to do: 1 for +,2 for -, 3 for x, 4 for /\n");
scanf_s("%u", &kind, 10);
while (kind<1||kind>4)
{
printf("wrong inputting, choose it again\n");
scanf_s("%u", &kind, 10);
}
question(kind);
scanf_s("%d", &answer,7);
while (answer != 111)
{
if (answer==a0)
{
printf("very good!\n");
question(kind);
}
else
{
printf("no,please try again\n");
}
scanf_s("%d", &answer,7);
}
}
void question(unsigned int k)
{
int a, b;
a = rand() % 10;
b = rand() % 10;
switch (k)
{
case 1: a0 = a+b;
printf("how much is %d add %d ?\n", a, b);
break;
case 2: a0 = a - b;
printf("how much is %d minus %d ?\n", a, b);
break;
case 3: a0 = a * b;
printf("how much is %d times %d ?\n", a, b);
break;
case 4: k = rand() % 3 + 1;
question(k);
break;
}
}