我有以下代码片段:
int main()
{
int x, R, m;
double Y, D, P;
cout << "Enter investment: ";
cin >> x;
cout << "Enter rate per year: ";
cin >> R;
cout << "Enter months: ";
cin >> m;
/* Convert to years. */
Y = m / 12;
D = x * pow ((1 + (R/100)), Y);
P = D - x;
cout << "Investment after " << Y << " years is " << D << " bucks.\n";
cout << "Profit is " << Y << " year(s) is " << P << " bucks.\n";
我的 cout 结果计算不正确,由于某种原因,我没有得到小数点。
我怀疑它与数据类型有关。