【问题标题】:Quadratic Formula - Error C2064: term does not evaluate to a function taking 1 arguments二次公式 - 错误 C2064:术语不计算为采用 1 个参数的函数
【发布时间】:2016-03-14 03:42:25
【问题描述】:

我收到了这个错误:

错误 1 ​​错误 C2064:术语不计算为采用 1 个参数的函数

上线:

discr=((pow(b, 2))-4(a*c));

二次公式程序代码:

#include "stdafx.h"
#include <iostream>
#include "math.h"
using namespace std;
float a, b, c, d,x1, x2, discr;
int ec2g(float a, float b, float c, float & x1, float & x2);
int _tmain(int argc, _TCHAR* argv[])
{
    cout<<"'a'"<<endl;
    cin>>a;
    cout<<"'b'"<<endl;
    cin>>b;
    cout<<"'c'"<<endl;
    cin>>c;
    if (ec2g(a, b, c, x1, x2)){
        cout<<x1<<x2<<endl;
    }
    else{
        cout<<"No solution"<<endl;
    }
    return 0;
} 

int ec2g(float a, float b, float c, float & x1, float & x2){
int solreal=0;
discr=((pow(b, 2))-4(a*c));
if(discr>0.0){
solreal=1;
x1=(-b+sqrt(discr)/(2.0*a));
x2=(-b-sqrt(discr)/(2.0*a));
}
return solreal;
}

知道如何解决这个问题吗?

【问题讨论】:

  • 首先去掉所有括号,除了调用pow的括号;他们不需要。在这些干扰消失后,问题应该很明显了。
  • 你的全局变量应该都是局部变量

标签: c++ arguments term evaluate reference-parameters


【解决方案1】:

你忘了乘法。所以编译器认为它看起来像一个函数调用。

4*(a*c)
 ^

附带说明,您也不需要pow。做吧:

discr = b * b - 4.0f * a * c;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-27
    • 2020-02-19
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多