gpt4 book ai didi

c - 简单的 'else if' 语句不起作用

转载 作者:行者123 更新时间:2023-11-30 15:12:09 24 4
gpt4 key购买 nike

#include <stdio.h>
#include <stdlib.h>

int main()
{
int age;

printf("Hello world! Please enter your age\n");
scanf("%d", &age);
if (age <= 50) {
printf("You are still young to change the world\n");
}
else if (70 >= age >50) {
printf("You are now old, but don't worry\n");
}
else {
printf("You are extremely old\n");
}
return 0;
}

我输入了 51 岁,结果显示“您已经非常老了”。 else if声明不起作用。

最佳答案

else if ( 70>=age>50 ){

在 C 语言中,这不是你这样做的方式。相反尝试这个 -

else if (age>50 && age <=70){    // age in between 50 and 70(including)

关于c - 简单的 'else if' 语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35237694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com