C program to convert Fahrenheit to Celsius always prints zero

后端 未结 7 1001
无人及你
无人及你 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 08:04

    try celsius = ((double)5/9) * (fahrenheit-32); Or you can use 5.0.

    The fact is that "/" looks at the operand type. In case of int the result is also an int, so you have 0. When 5 is treated as double, then the division will be executed correctly.

提交回复
热议问题