Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C编程温度转换问题_C_Equation_Temperature - Fatal编程技术网

C编程温度转换问题

C编程温度转换问题,c,equation,temperature,C,Equation,Temperature,书中的问题: 编写一个将温度从华氏温度转换为摄氏温度的程序,您的程序应: 提示用户要进行哪种类型的转换 提示用户输入要转换的温度 我得到了不正确的输出。我不确定哪里出了问题。我对c语言还不熟悉。非常感谢您的帮助。 这是我的密码: #include <stdio.h> #include <stdlib.h> int main() {int f, c, f_or_c; printf("Would you like to convert Fahrenheit

书中的问题:

编写一个将温度从华氏温度转换为摄氏温度的程序,您的程序应:

  • 提示用户要进行哪种类型的转换
  • 提示用户输入要转换的温度
  • 我得到了不正确的输出。我不确定哪里出了问题。我对c语言还不熟悉。非常感谢您的帮助。 这是我的密码:

      #include <stdio.h>
      #include <stdlib.h>
    
    
     int main()
     {int f, c, f_or_c;
    
     printf("Would you like to convert Fahrenheit (1) or Celsius (2)?\n");
     scanf("%d", &f_or_c);
    
     if(f_or_c==1)
     {
        printf("Enter the temperature in Fahrenheit to convert?\n");
        scanf("%d", &c);
        f = 1.8*c + 32.0;
        printf("Celsius of %d is %d degrees.\n");
    
     }
     if(f_or_c==2)
     {
        printf("Enter the temperature in Celsius to convert?\n");
        scanf("%d", &f);
        c = (f-32)*5/9;
        printf("Fahrenheit of %d is %d degrees.\n");
     }
     return 0;
     }
    
    #包括
    #包括
    int main()
    {int f,c,f_或c;
    printf(“您想转换华氏(1)还是摄氏(2)?\n”);
    scanf(“%d”、&f_或_c);
    如果(f_或c==1)
    {
    printf(“输入要转换的华氏温度?\n”);
    scanf(“%d”、&c);
    f=1.8*c+32.0;
    printf(“摄氏%d是%d度。\n”);
    }
    如果(f_或c==2)
    {
    printf(“以摄氏度为单位输入要转换的温度?\n”);
    scanf(“%d”、&f);
    c=(f-32)*5/9;
    printf(“华氏%d度是%d度。\n”);
    }
    返回0;
    }
    
    我猜您只是没有打印出值,但其他一切看起来都很好

    printf("Fahrenheit of %d is %d degrees.\n");
    
    你没有打印任何变量

    这可能对你有用

    printf("Fahrenheit of %d is %d degrees.\n", f, c); 
    
    您可以在此处查看
    printf
    的一般用法

    您的问题是什么?您得到的是哪种“不正确的输出”?您好,欢迎来到stack overflow。为了帮助您,我们需要知道您的问题是什么,这是您在上面复制的代码。代码是否运行并在某个点中断?将错误消息添加到您的问题中!它只是给你意外的输出吗?在您的问题中添加预期输出和实际输出。获取错误输出请帮助您必须添加您的输出和预期输出,以便我们帮助您……:)这确实让你想知道观察到了什么“不正确的输出”,不是吗?当你期望32,结果是2037481959(或其他什么),这通常意味着你把错误的东西(或根本没有)传递给printf。谢谢你这么做了!新的在这方面,不能相信它是那么简单。现在我看到的评论,在那里的例子输出给出。事实上,这是一个很好的线索。