csdn_xjm 2023-03-03 14:56 采纳率: 87.5%
浏览 21
已结题

华氏度和摄氏度温度转化问题

华氏度和摄氏度温度转化问题,为什么输入华氏度64,输出就成了0了,摄氏度应该是17.7777。

img

img

  • 写回答

2条回答 默认 最新

  • MarkHan_ 2023-03-03 15:00
    关注

    该回答引用GPTᴼᴾᴱᴺᴬᴵ
    代码存在一些语法错误和逻辑错误,可能会导致结果不正确。下面是修正后的代码:

    #include <stdio.h>
    
    float f_to_c(float input);
    float c_to_f(float input);
    
    int main()
    {
        int choice;
        float input, output;
        
        printf("1 for f to c, 2 for c to f:\n");
        scanf("%d", &choice);
        
        if (choice == 1)
        {
            printf("please input f:\n");
            scanf("%f", &input);
            output = f_to_c(input);
            printf("f is %.1f, c is %.1f\n", input, output);
        }
        else if (choice == 2)
        {
            printf("please input c:\n");
            scanf("%f", &input);
            output = c_to_f(input);
            printf("c is %.1f, f is %.1f\n", input, output);
        }
        
        return 0;
    }
    
    float f_to_c(float input)
    {
        float output;
        output = (5.0/9)*(input-32);
        return output;
    }
    
    float c_to_f(float input)
    {
        float output;
        output = (9.0/5)*input+32;
        return output;
    }
    
    
    

    修正后的代码会首先要求用户输入要进行的转换类型,然后根据用户选择分别要求输入温度值,并计算输出转换后的温度值。注意在读取输入值时要使用正确的格式符,例如读取浮点数时应该使用 %f 而不是 %d。另外,输出时使用 %.1f 可以控制小数点后的位数。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月11日
  • 已采纳回答 3月3日
  • 创建了问题 3月3日

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集