全部文本 #156622 原始 编辑

Bad if statements

公开 c v1 · 不可变
·已发布 2006-08-31 21:47 UTC
渲染后的文本正文
#include <stdio.h>//Program to convert celsius to fahrenheit or vis versa.int main (void) {        char unit[9];    double tempc, tempf;    double toc, tof;        printf("Would you like to start with Celsius or Fahrenheit?\n");    scanf("%s",&unit);        printf("What temperature?");    if (unit=="Celsius")        scanf("%lf", &tempc);    else        scanf("%lf", &tempf);                    tof=1.8*tempc + 32;    toc=(tempf-32)/1.8;               if (unit=="Celsius")       printf("That temperature converts to %.0f degrees Fahrenheit.\n", tof);    else       printf("That temperature converts to %.0f degrees Celsius.\n", toc);                 system("pause");    return 0;}