【发布时间】:2018-09-18 08:47:19
【问题描述】:
我是一个非常新手的程序员,对我在做什么一无所知。除了阅读文档。
我的程序没有让用户有时间立即输入 unwires,它只是说“否”的答案。我做错了什么?
我制作这个程序是为了给我的朋友开个玩笑(就像 AI 出了问题)
这是我的代码:
#include <stdio.h>
int main() {
int yorn;
printf("do you have friends? please awnser yes or no.");
scanf("%d", &yorn );
if (yorn = "yes") {
printf("no, you dont. please reload the program if you want to change your awnser.");
}
else if (yorn = "no") {
printf("i can be your friend. your BEST friend.");
}
return 0;
}
【问题讨论】:
-
这取决于输入的类型。 (双关语,你的变量类型和你描述的用户类型不匹配)
-
真@BenVoigt。我已经回答建议他进行更改。
-
在启用警告的情况下编译会在这里发现多个问题(滥用单个
=并将指针值分配给整数)。值得学习如何将编译器配置为最高警告级别(gcc中的-Wall)并始终注意警告。