首页 > 解决方案 > 为什么它给出0答案?

问题描述

#include <iostream>
using namespace std;
int main()
{
double basic = 1000;
double DA = (10/100) * basic;
double HRA = (30/100) * basic;
cout<<"DA = "<<DA<<endl; // why the answer is 0 ?
cout<<"HRA = "<<HRA<<endl; // why the answer is 0 ?
return 0;
}

请帮助我....我不明白为什么 DA 和 HRA 给出的答案是 0?

标签: c++

解决方案


10/100 = 0 因为 10 和 100 都是 int 并且它们的结果也将是 int。

尝试 10/100.0

30/100.0


推荐阅读