未来值公式显示疯狂巨大数字的输出



我显然是新手:( 这是我的公式,但这是我甚至可以让它运行的唯一方法。它只是显示一个疯狂的大数字,我不明白怎么写。请怜悯我的新手灵魂...

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(int argc, char** argv) {
float F, P, i;
int t;
cout << "Enter how much money is currently in the account: ";
cin >> P;
while (P < 1)   // Amount can not be less that $1
{
cout << "Value must be at least $1, enter another amount: ";
cin >> P;                   
}
cout << "Enter the monthly interest rate: ";
cin >> i;
cout << "Enter how many months this money will be in the account: ";
cin >> t;

F = P * pow( 1 + i,(t * 12));
cout << fixed << showpoint;
cout << "Original:" << setfill(' ') << setw(20) << "$" << P << endl;
cout << "Monthly Interest:" << setfill(' ') << setw(12) << "$" << i << endl;
cout << "Future amount:" << setfill(' ') << setw(15) << "$" << F;

return 0;
}

正如评论中已经提到的,该问题位于您的兴趣公式中。请将其更改为以下内容:

F = P * pow( 1 + i/(P * 12),(t * 12));

当您以 $ 为单位插入月利率i时,因此作为绝对值,您需要计算相对i / P。此外,还缺少复利频率,这应该在每个月在您的问题中。因此,必须在分母中添加 12

。请查看维基百科以获取更多信息,尤其是在计算部分。

希望对您有所帮助。

最新更新