2014-02-27 170 views
1

我知道我的工作是草率的,这是我在这堂课中的第四个任务。任何帮助将不胜感激,谢谢。错误:无法在作业中将'double'转换为'double(double,double,double)'

double getPrincipal(0); 
double getRate(0); 
double getYears(0); 
double computeAmount(double getPrincipal, double getRate, double getYears); 
double displayAmount(double principal, double rate, double years, double amount); 

cout << "what is the principal ammount?" << endl; 
cin >> getPrincipal; 

cout << "What is the percentage rate?" << endl; 
cin >> getRate; 

cout << "Over how many years will the money stay in the bank?" << endl; 
cin >> getYears; 

computeAmount = pow((1 + getRate/100),getYears); // This is where i got the error 
+0

您的意思是声明在此代码块/使用lambda函数? –

回答

1

当编译器是想告诉你,你不能一个变量如果你想这是一个函数分配给功能

,定义它&调用它。

如果您希望它是一个变量,请将其声明为变量。

3

您试图通过分配一个值的函数与variables搞乱functions

double computeAmount(double getPrincipal, double getRate, double getYears); 

通过这条线,你声明computeAmount()是谁需要3个double S作为它的参数和返回double的功能。

但是,在这条线上,

computeAmount = pow((1 + getRate/100),getYears); 

你试图使用它作为一个变量。

取决于你的目的是什么,你可能想要改变这两行中的一行。例如,可以删除第一行,第二行更改为:

double computeAmount = pow((1 + getRate/100),getYears); 
+0

_'You can not assign a value to a function.'_呃,实际上你可以:'virtual void foo()= 0;' –

+1

@πάνταῥεῖ这不是一个赋值,而是一种指定纯虚拟的语法方式功能。 –

+0

@ZacHowland你实际上可以使用“0”以外的值(甚至对此也有合理的用例)。 –

1

computeAmount是你定义一个返回double和需要3个double参数的函数的名称。 pow返回double

把上面一行

double computedAmount = pow((1 + getRate)/100, getYears); 
     ^^^^^^^^^^^^^^ -- notice this is no longer the function name, but a new variable 
1

你声明的名称computeAmount的函数名

double computeAmount(double getPrincipal, double getRate, double getYears); 

所以这种说法

computeAmount = pow((1 + getRate/100),getYears); 

有没有意义。因为computeAmount是一个函数名,那么在上面的espression中将它转换为指向函数的指针,并且您试图将函数pow返回的某个double值分配给此指针。

1

computeAmount被声明为一个函数,但用于'='运算符的左侧。 解决办法:重新申报computeAmount只是一个双:

double computeAmount; 
相关问题