C program to convert Fahrenheit to Celsius always prints zero

后端 未结 7 1140
无人及你
无人及你 2020-11-22 07:09

I need some help with a program for converting Fahrenheit to Celsius in C. My code looks like this

#include 
int main(void)
{
    int fahrenhe         


        
7条回答
  •  佛祖请我去吃肉
    2020-11-22 07:43

    When dealing with floats, it needs to be 5.0f / 9.0f.

    When dealing with doubles, it needs to be 5.0 / 9.0.

    When dealing with integers, remainders/fractions are always truncated. 5 / 9 results between 0 and 1, so it is truncated to just 0 every time. That multiplies the other side by zero and completely nullifies your answer every time.

提交回复
热议问题