Why does division result in zero instead of a decimal?

前端 未结 5 625
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 05:38

Teaching myself C and finding that when I do an equation for a temp conversion it won\'t work unless I change the fraction to a decimal. ie,

tempC=(.555*(tempF

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-21 06:11

    5/9 is an integer division not a floating point division. That's why you are getting wrong result.

    Make 5 or 9 floating point variable and you will get correct answer.

    Like 5.0/9 OR 5/9.0

提交回复
热议问题