Fahrenheit to Celsius conversion

前端 未结 3 1070
伪装坚强ぢ
伪装坚强ぢ 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:54

    When you operate on two integers, results is not converted to double. It remains as int only. To get the result into double, at least one of the numbers should be double. e.g.

           double ft = 5.0/9; //double
           double ft = 5/9.0;//double
           double ft = 5.0/9.0;//double
    

    While

            double ft = 5/9; //int 0
    

    Please refer the Floating Point Operations Specification for details.

提交回复
热议问题