【发布时间】:2021-10-09 01:41:53
【问题描述】:
这些天我在测试我的 C 知识,我正在编写一个关于 if/else 语句的小程序。
代码应该可以工作(我希望如此),因为它之前编译过几次,但现在由于某种原因它抛出了这个错误:
我的代码:
#include <stdio.h>
void main() { /*int main() { simply brought back the same error, I know it's the right one.*/
int myNum;
printf("Enter a number: ");
myNum == scanf("%d");
if(myNum > 14) {
printf("Your number is bigger than 14.");
} else if(myNum == 14) {
printf("Your number is equal to 14.");
} else if(myNum > 14) {
printf("Your number is smaller than 14.");
} else {
printf("Oops, not a number !");
}
return 0;
【问题讨论】:
-
阅读scanf manual 并搜索有关如何使用它的教程。我非常怀疑这段代码可以在任何地方使用。必须是
int result = scanf("%d", &myNum); -
感谢您的回答,我会尝试并通知您:)
-
另外,
==是一个比较,而不是一个赋值。 -
你在手机上写代码吗?
-
@yano 我也想知道。很酷,我猜! (不过,最好不要沉迷于过多的 UB —— 可能会以 demons coming out of the phone 告终!)