#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char *argv[])
{
double amount, rate, time, interest, month;
interest = rate/(12.0*100);
month = (amount * rate)/1.0 -(1.0 + interest), pow(time*12);
cout << "What is the amount of the loan? $ ";
cin >> amount;
cout << "What is the annual percentage rate? ";
cin >> rate;
cout << "How many years will you take to pay back the loan? ";
cin >> time;
cout <<"\n-------------------------------------------------------\n";
cout << "Amount Annual % Interest Years Monthly Payment\n\n\n";
cout <<amount <<" " <<rate <<" " <<time << " " <<month;
cout <<"\n\n";
system("PAUSE");
return EXIT_SUCCESS;
}
我在这里收到错误,我不确定如何正确使用pow功能。根据问题的公式是:
Monthly payment = (loan amount)(monthly interest rate) / 1.0 - (1.0 + Monthly interest rate)^-(number of months)
这是我遇到问题的行
月=(金额*费率)/1.0 - (1.0 +利息),pow(时间* 12);
感谢您的帮助
答案 0 :(得分:2)
std::pow
接受两个参数,如此
pow (7.0,3)
所以你的代码应该更像这个
month = (amount * rate)/1.0 - std::pow( (1.0 + interest), 12);
您的代码也有其他缺陷,就像您在设置值之前进行计算一样。