将华氏温度转换为摄氏的C程序始终显示零 [英] C program to convert Fahrenheit to Celsius always prints zero

查看:36
本文介绍了将华氏温度转换为摄氏的C程序始终显示零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关将华氏温度转换为摄氏温度的程序的帮助.我的代码如下所示:

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

#include <stdio.h>
int main(void)
{
    int fahrenheit;
    double celsius;

    printf("Enter the temperature in degrees fahrenheit:\n\n\n\n");
    scanf("%d", &fahrenheit);
    celsius = (5 / 9) * (fahrenheit - 32);
    printf("The converted temperature is %lf\n", celsius);

    return 0;
}

每次执行它的结果都是0.000000.我知道我遗漏了一些东西,但无法弄清楚是什么.

Every time I execute it it the result is 0.000000. I know I'm missing something but can't figure out what.

推荐答案

5/9将导致整数除法,该值将等于0

5/9 will result in integer division, which will = 0

改为尝试 5.0/9.0 .

这篇关于将华氏温度转换为摄氏的C程序始终显示零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆