gpt4 book ai didi

c - 尝试使用基本的音频电平出纳器,但给出了错误的答案

转载 作者:太空宇宙 更新时间:2023-11-04 04:15:09 25 4
gpt4 key购买 nike

#include <stdio.h>

int main()
{
float A;
printf("Pls write the decibel\n");
scanf("%f",&A);
if (49<A,60>A)
{printf("quiet\n");}
else if (70>A,59<A)
{printf("Anoying\n");}
else if (80>A,69<A)
{printf("to Anoying\n");}
else if (90>A,79<A)
{printf("Very Anoying\n");}
else if (101>A,89<A)
{printf("Extreamly Anoying\n");}
else if (A>100)
{printf("You Are Dead\n");}
else if (50>A);

{printf("To Low\n");}
return 0;
}

假设我写了超过 100 个,它说的太低了,同时又很烦人,而且没有一个是真的,我该怎么办?

谢谢

最佳答案

  • else if (50>A); 之后有一个分号结束语句以便下一个 printf 无论如何都会被执行。
  • 您还应该使用逻辑与运算符 (&&) 而不是逗号运算符在你的条件中。

修改后的程序为:

#include <stdio.h>

int main()
{
float A;
printf("Pls write the decibel\n");
scanf("%f",&A);
if (49<A && 60>A)
{printf("Quiet\n");}
else if (70>A && 59<A)
{printf("Annoying\n");}
else if (80>A && 69<A)
{printf("Too Annoying\n");}
else if (90>A && 79<A)
{printf("Very Annoying\n");}
else if (101>A && 89<A)
{printf("Extremely Annoying\n");}
else if (A>100)
{printf("You Are Dead\n");}
else if (50>A)
{printf("Too Low\n");}
return 0;
}

输出:

Pls write the decibel                                                                                                          
101
You Are Dead

关于c - 尝试使用基本的音频电平出纳器,但给出了错误的答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53020626/

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