很抱歉,如果之前已经提出这个或者是一个愚蠢的问题,但我是网站和C的新手。所以,当我运行此代码时,当我输入答案时,任何答案,无论是对还是错,它说什么时候应该说if语句。这是代码:
#include <stdio.h>
int main()
{
int x;
printf("1+1=");
scanf("%d", &x);
if("x==2"){
printf("Watch out, we got a genius over here!");
}
else {
printf("I don't even know what to say to this...");
}
return 0;
}
答案 0 :(得分:9)
你需要
if(x==2)
没有引号
答案 1 :(得分:2)
试试这个
#include <stdio.h>
int main()
{
int x;
printf("1+1=");
scanf("%d", &x);
if(x==2){
printf("Watch out, we got a genius over here!");
}
else {
printf("I don't even know what to say to this...");
}
return 0;
}
答案 2 :(得分:2)
试
#include <stdio.h>
int main()
{
int x;
printf("1+1=");
scanf("%d", &x);
//modify this line if("x==2"){
if(x==2){
printf("Watch out, we got a genius over here!");
}
else {
printf("I don't even know what to say to this...");
}
return 0;
}
答案 3 :(得分:0)
“x == 2”是一个字符串文字位于内存中,它有一个地址。地址几乎从不为0(除了某些架构,最值得注意的是嵌入式系统)所以表达式始终是真的