结果并不合适

时间:2017-03-23 09:44:50

标签: c++ cmath

好的,所以我有这个代码,据说可以得到复合利益的平衡,据说方程就像这样

w(1 + x / y)升至yz

我生产的代码就是这样  像这样

#include<iostream>
#include<cmath>

using namespace std;


float power(int x,int y, int z)
{
float pwr, term;
pwr =(y+z);
term = (1.0+x/static_cast<float>(y));
return pwr;
}


float interest(int w, int x, int y, int z, float pwr, float term)
{
float ans;
ans = pow(w*term,pwr);
return ans;
}

main()
{

int w,x,y,z;
float pwr, ans, term;

cout << "\n Enter value for w: ";
cin >> w;
cout << "\n Enter value for x: ";
cin >> x;
cout << "\n Enter value for y: ";
cin >> y;
cout << "\n Enter value for z: ";
cin >> z;

pwr = power(x,y,z);
ans = interest( w, x, y, z,pwr, term);

cout << "\nYour balance is Php "<<ans;




}

它运行正常...... 但假设给定的w x y和z的值分别为5,2,4,2。结果应该是128.145 但输入数字后的输出是6 ... 帮助

1 个答案:

答案 0 :(得分:0)

试试这个,你错过了findterm的功能。

#include<iostream>
#include<cmath>

using namespace std;


float power(int x,int y, int z)
{
float pwr;
pwr =(y+z);
return pwr;
}

float findterm(int x, int z)
{
float term;
term = (1.0+x/static_cast<float>(y));
return term;
}

float interest(int w, int x, int y, int z, float pwr, float term)
{
float ans;
ans = (w*term,pwr);
return ans;
}

main()
{

int w,x,y,z;
float pwr, ans, term;

cout << "\n Enter value for w: ";
cin >> w;
cout << "\n Enter value for x: ";
cin >> x;
cout << "\n Enter value for y: ";
cin >> y;
cout << "\n Enter value for z: ";
cin >> z;

pwr = power(x,y,z);
term = findterm(x,z);
ans = interest( w, x, y, z,pwr, term);

cout << "\nYour balance is Php "<<ans;

}