我知道我的作业很草率,这是我在这节课上的第四次作业。任何帮助都将不胜感激,谢谢。
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发布于 2014-02-28 02:38:42
你试图给一个函数赋值,这会把functions和variables搞乱。
double computeAmount(double getPrincipal, double getRate, double getYears);通过这一行,您将computeAmount()声明为一个函数,该函数接受3个double作为其参数并返回一个double。
但是,在这条线上,
computeAmount = pow((1 + getRate / 100),getYears);您正在尝试将其用作变量。
取决于您的目的,您可能想要更改这两行中的一行。例如,您可以删除第一行,并将第二行更改为:
double computeAmount = pow((1 + getRate / 100),getYears);发布于 2014-02-28 02:38:35
正如编译器试图告诉您的那样,您不能将变量赋值给函数
如果你想让它成为一个函数,定义它并调用它。
如果希望它是一个变量,请将其声明为变量。
发布于 2014-02-28 02:39:43
computeAmount是您定义的函数的名称,该函数返回一个double并接受3个double参数。pow返回一个double。
将该行更改为
double computedAmount = pow((1 + getRate) / 100, getYears);
^^^^^^^^^^^^^^ -- notice this is no longer the function name, but a new variablehttps://stackoverflow.com/questions/22077348
复制相似问题