私は 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");
}