对如何使用pow()函数来负功率的东西感到困惑

confused on how to use the pow() function to negativley power something?

本文关键字:功率 pow 何使用 函数      更新时间:2023-10-16

我不确定我是否在正确的地方设置了pow函数,但我不知道如何将月设置为-月供电。

这是原始的公式,我应该以此为基础:本金*(率/12)/(1 -(1 +税率/12)^个月)

我得到错误信息:

错误C2064: term不计算为带有1个参数的函数 下面是我的代码:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int y = -1;
    double months;
    double principle = 1000;
    double rate = 7.20;
    double monthly_pay;
    cout << "Please enter the number of months you have to pay back the loan:";
    cin >> months;
    monthly_pay = principle*(rate/12)/((1-pow((1+rate/12), -months)));
    cout << monthly_pay << endl;
    return 0;
}
double pow (double base, double exponent);
      //Returns the value of the first argument raised to the power of the second argument.

所以改变

monthly_pay = principle*(rate/12)/(1-(1+rate/12)pow(months, y);

monthly_pay = principle*(rate/12)/((1-pow((1+rate/12), -months));

我把你的算法分解成更小的函数(我希望你不介意)。我想出了这个代码,编译刚刚好为我。我相信你们已经理解了这个概念,你们只是忘了用星号乘以函数pow(a,b)

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int y = -1;
double months;
double principle = 1000;
double rate = 7.20;
double monthly_pay;
double a, b;

cout << "Please enter the number of months you have to pay back the loan:";
cin >> months;
a = rate / 12;
b = pow(months, y);
monthly_pay = (principle * a) / (1 - (1 + a) * b);

cout << monthly_pay << endl;

return 0;

}

我希望这对你有帮助!