int main() {
printf ("Welcome in Lorempipsuland.h\n");
printf ("Choose one oh the paths:\n");
printf ("1-Nerd programmer's Rocky Mountains\n");
printf ("2-Olografic Banshee's Lakes\n");
c = getchar();
if (c == 1) {
printf ("You entered in the Nerd programmer's Rocky Mountains\n");
printf ("Oh no, you met the solitaire programmer, do you want combat? Yes(1) or Not(2)?\n");
a = getchar();
if (a == 1) {
printf ("You decided to fight, PREPARE!\n");
}
else if (a == 2) {
printf ("Coward!, but now go away, we have to walk lot");
}
}
else if (c == 2) {
printf ("You entered in Holographic Banshee's lakes\n");
printf ("Oh no, that's an Holographic Banshee!\n");
}
我在kali linux终端上,我遇到了问题,因为当终端执行代码时,读取所有if条件,直到到达第一个if,然后终端返回到根kali,不执行其他if和else if状况。
你能帮我吗?
最佳答案
这不是比较 char
的方式。
char
的方式
(c == '1')
关于c - C中if语句的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34515041/