【发布时间】:2014-07-01 02:10:10
【问题描述】:
书中的问题:
编写一个程序,将温度从华氏温度转换为摄氏温度,你的程序应该:
- 提示用户他们想要进行哪种类型的转换。
- 提示用户输入他们想要转换的温度。
我得到不正确的输出。我不确定我哪里出错了。我是 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;
}
【问题讨论】:
-
你的问题是什么?
-
你得到什么样的“错误输出”?
-
嗨,欢迎来到堆栈溢出。为了让我们帮助您 - 我们需要知道您在上面复制的代码是什么问题。代码是否运行然后在某个时候中断?将错误消息添加到您的问题中!它只是给你意想不到的输出吗?将预期输出和实际输出添加到您的问题中。
-
得到不正确的输出请帮助
-
您必须添加您的输出和预期输出才能让我们帮助您... :)
标签: c equation temperature