Fahrenheit to Celsius conversion

前端 未结 3 1066
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 06:17

I\'m trying to write a program that converts temperatures expressed in degree Fahrenheit to degree Celsius. The user enters a Fahrenheit value and the program prints out the

3条回答
  •  爱一瞬间的悲伤
    2020-12-22 06:58

    double ft = 5 / 9 ;
    

    The line above doesn't do what you think it does.
    Because 5 and 9 are both integers, it does integer division. The fact that you're assigning the result to a double doesn't matter, if both operands are integers, you will get integer math.

    So ft is always 0, so cel is always 0

    Try

    double ft = 5.0/9.0;
    

提交回复
热议问题