C编程-温度转换问题

标签 c equation temperature

书中的问题:

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

  1. 提示用户想要进行哪种类型的转化。
  2. 提示用户输入想要转换的温度。

我得到的输出不正确。我不确定哪里出了问题。我是 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;
 }

最佳答案

我的猜测是您只是没有打印出值,但其他一切看起来都不错。

printf("Fahrenheit of %d is %d degrees.\n");

您没有打印任何变量。

这可能对你有用

printf("Fahrenheit of %d is %d degrees.\n", f, c); 

您可以在此处查看 printf 的一般用法 http://www.cplusplus.com/reference/cstdio/printf/

关于C编程-温度转换问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24501527/

相关文章:

delay - 在具有延迟的系统中调整pid

java - 如何在native中写/读直接的ByteBuffer?

c - 如何获得结构体中正确的偏移地址

c - 字符输入的 Scanf 特定错误条件

c++ - 返回错误答案的简单 C++ 二次方程求解器

math - 计算飞行过程中条件变化的弹道轨迹

Highcharts - 温度计

服务器向客户端发送消息时android native Binder 崩溃

Java 方程/表达式生成器

java - 如何更改二维数组中的所有值?