对如何使用pow()函数来负功率的东西感到困惑
confused on how to use the pow() function to negativley power something?
我不确定我是否在正确的地方设置了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;
}
我希望这对你有帮助!
相关文章:
- 在C++中如何在没有pow的情况下进行基础计算
- 理解GCC中的std::pow实现
- 子例程,不使用 pow,并带有参数和返回
- 整数溢出,最大值为 pow(10,19)
- 在 while 循环中使用 pow() 函数 C++
- 如何编写计算功率的循环
- 在C++不使用 POW 的情况下处理负指数
- C++ 中 pow() 函数的输出没有给出准确的答案
- 没有匹配'pow'功能
- 为什么 while ((i <= 9) && square == pow(i, 2)) { cou
- Arduino Pow() 和 Armstrong 数问题
- 2分频浮动功率的优化
- C++在不使用pow或循环的情况下计算一个数字的幂
- 让constexpr在OSX上的C++17中使用pow
- Why (int)pow(2, 32) == -2147483648
- 错误:"int pow(double,int)"与上一个声明int pov(double a,int
- Pow 在 C++ 中无法按预期工作
- C++使用负矢量大小计算的 pow 行为
- 2 接 x86_64 的快速浮点功率
- 对如何使用pow()函数来负功率的东西感到困惑