C ++程序将华氏度转换为摄氏度 [英] C++ program converts fahrenheit to celsius

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

问题描述

有人可以帮助我理解为什么这个输出为0吗?

Can someone help me understand why this gives an output of 0?

#include <iostream>                        
using namespace std;                       

int main() {                               
    float celsius;                         
    float fahrenheit;

    cout << "Enter Celsius temperature: "; 
    cin >> celsius;
    fahrenheit = (5/9) * (celsius + 32);
    cout << "Fahrenheit = " << fahrenheit << endl;

    return 0;                             
}


推荐答案

(5/9)将默认计算为整数除法,将为零。尝试(5.0 / 9)

(5/9) will by default be computed as an integer division and will be zero. Try (5.0/9)

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

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