我想做一个类似验证码的检查,但它所做的只是崩溃。 代码有什么问题吗? 我的代码如下所示:
printf("I need to make some tests to ensure that you are a human being.\n");
printf("Let's start\n");
int randomNumber1 = rand() % 100;
int randomNumber2 = rand() % 100;
printf("What is %d + %d ?\n", randomNumber1, randomNumber2);
int randomNumberSum = randomNumber1 + randomNumber2;
int solution;
printf("%d \n", randomNumberSum);
scanf("%d", solution);
if (solution = randomNumberSum) {
printf("Good job human !\n");
} else {
printf("Nice try, bot \n");
}
最佳答案
当使用scanf()
读取整数时,您需要提供int
变量的地址:
scanf("%d", &solution);
您还需要在 if
语句中使用 ==
(比较)而不是 =
(赋值)。
关于C 如何比较 2 个 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38551224/