C: converting Farenheit to Celsius

前端 未结 3 619
我在风中等你
我在风中等你 2020-12-02 03:10
int main (void)
{
    int fahrenheit; // fahrenheit stands for fahrenheit
    double c; // c stands for celsius

    printf(\"Enter your fahrenheit, we\'ll covnvert          


        
3条回答
  •  天涯浪人
    2020-12-02 03:28

    Short answer: Operations on integers return integers even if the variable you store the result on is a double. Divisions between integers are truncated.

    You should write this instead:

    c = 5.0/9.0 * (fahrenheit - 32.0);
    

    Adding a ".0" (or even just a ".") to your constant makes them floating point values.

提交回复
热议问题