0
#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);

谢谢您的帮助

4

1 回答 1

2

std::pow像这样接受两个参数

pow (7.0,3) 

所以你的代码应该更像这样

month = (amount * rate)/1.0 - std::pow( (1.0 + interest), 12);

您的代码也有其他缺陷,例如在设置值之前进行计算。

于 2013-03-10T08:29:15.347 回答