我得到一个错误"表达式不能用作函数"

时间:2016-10-27 13:52:07

标签: c++

#include <iostream>

using namespace std; 
int main()
{
    float x;
    float y;
    cin >> x;
    y = (7*((x-3)^2)-6(x-4)+5) ;
    cout<<y;

    return 0;
}

为什么这会一直给我错误&#34;表达不能用作函数&#34; ?

3 个答案:

答案 0 :(得分:4)

这是一个语法问题:

y = (7*((x-3)^2)-6(x-4)+5) ;
                 ^

你需要明确地相乘,否则看起来你试图调用函数6

y = (7*((x-3)^2)-6*(x-4)+5) ;

然后,您需要处理因尝试使用^float进行按位异或(int运算符为按位异或)而导致的错误。

test.cpp:9:19: error: invalid operands of types ‘float’ and ‘int’ to binary ‘operator^’

如果您打算使用电源,则需要采用不同的方式。见http://en.cppreference.com/w/cpp/numeric/math/pow

答案 1 :(得分:1)

这个表达式:

uv_write_t

表示带有参数(x-4)的6(x-4) 的调用函数,因为6显然不是函数而导致错误。 C ++不是数学,你不能省略乘法。

答案 2 :(得分:0)

你需要

#include <cmath> or <math.h>

如果你想加电。你需要使用pow功能。

pow((x-3),2)