【发布时间】:2021-10-30 07:31:14
【问题描述】:
美好的一天!我尝试使用 C 制作一个简单的计算器,用于我的第一个关于华氏到摄氏度之间转换的项目,反之亦然。但它不起作用,有人可以告诉我我想念什么吗?
这是我的代码:
#include <stdio.h>
int main()
{
double temp, fahrenheit, celsius;
char answer[2];
printf("Type 'CF' if you want to convert from celsius to fahrenheit, and 'FC' if you want to convert from fahrenheit to celcius: ");
fgets(answer, 2, stdin);
fahrenheit = (temp * 1.8) + 32;
celsius = (temp - 32) * 0.5556;
if(answer == "CF"){
printf("Type the temperature here: ");
scanf("%lf", &temp);
printf("Answer: %f", fahrenheit);
}
else if(answer == "FC"){
printf("Type the temperature here: ");
scanf("%lf", &temp);
printf("Answer: %f", celsius);
}
return 0;
}
【问题讨论】: