我正在学习 C 并且正在使用我最近完成的 Python 书中的一些练习题。我的 C 书在邮件中,但我想抢先一步。我正在编写一个简单的温度转换程序,由于某种原因,它总是跳到我的条件中的“Else”子句......我确定我错过了一些简单的东西,但我似乎无法弄清楚。有任何想法吗?:
#include<stdio.h>
main()
{
float temp_c, temp_f;
char convert_from[1];
printf("Convert from (c or f): ");
scanf("%c", &convert_from);
if(convert_from == "c")
{
printf("Enter temperature in Celsius: ");
scanf("%f", &temp_c);
temp_f=(1.8*temp_c)+32;
printf("The temperature in Fahreinheit is: %f \n", temp_f);
}
else if(convert_from == "f")
{
printf("Enter temperature in Fahreinheit: ");
scanf("%f", &temp_f);
temp_c=(temp_f/1.8)-32;
printf("The temperature in Celsius is: %f \n", temp_c);
}
else
printf("Invalid choice. \n");
}