【问题标题】:Wrong result outputted错误的结果输出
【发布时间】:2019-07-14 16:25:37
【问题描述】:

我正在编写一个输出“干得好!”的代码。如果输入的 GPA 超过 3.5 并且“如果输入的 GPA 低于 2.0,你需要更加努力学习。但是它输出不正确。

if(gpa[i] >= 2.0){
printf("You need to study harder! \n");
}
else if(gpa[i] <= 3.5){
printf("Nice work! \n");
}

我希望输出“干得好!”如果gpa超过3.5。 如果gpa低于2.0,“你需要更加努力学习”。

【问题讨论】:

  • &gt;= 读作“大于或等于”。我喜欢将&lt; 或&gt; 的开放端视为较大的一端...所以,当a &gt; b ... 这意味着a(最接近开放端)大于@987654327 @.
  • 调试器在第一个 if 语句之前显示的 gpa[i] 的值是什么

标签: c arrays sorting


【解决方案1】:

您与 if 条件中的逻辑运算符混淆了。 应该是这样的

if(gpa[i] <= 2.0){
    printf("You need to study harder! \n");
}
else if(gpa[i] >= 3.5){
    printf("Nice work! \n");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    • 1970-01-01
    • 2014-09-16
    相关资源
    最近更新 更多