gpt4 book ai didi

c - 输出结果错误

转载 作者:行者123 更新时间:2023-11-30 14:37:48 25 4
gpt4 key购买 nike

我正在编写一个代码,它将输出“干得好!”如果输入的 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");
}

我期望输出“nice work!”如果gpa超过3.5。如果 GPA 低于 2.0,则“你需要更加努力地学习”。

最佳答案

您对 if 条件中的逻辑运算符感到困惑。应该是这样的

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

关于c - 输出结果错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57029167/

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