【问题标题】:what is wrong with my code. I am not getting required output. when in executed this code in one of the online compiler it is no giving required output我的代码有什么问题。我没有得到所需的输出。当在其中一个在线编译器中执行此代码时,它没有提供所需的输出
【发布时间】:2021-08-28 00:08:00
【问题描述】:
#include<stdio.h>

int main(){

    int age;
    printf("enter your age:");
    scanf("%d",&age);
    
    if(age>=18 || age<=70){
        printf("you can drive");
    }else{
        printf("you cannot drive");
    }
    return 0;
}

我没有得到所需的输出 “输入你的年龄:你会开车”

【问题讨论】:

  • if(age&gt;=18 &amp;&amp; age&lt;=70)
  • || = 一个或另一个。 &amp;&amp; = 一个又一个

标签: c if-statement conditional-statements operators


【解决方案1】:

你应该改用这个条件:if(age&gt;=18 &amp;&amp; age&lt;=70)

【讨论】:

    【解决方案2】:

    如果您使用||,您的范围将是开放的。

    【讨论】:

      猜你喜欢
      • 2021-09-06
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多