C ++ error =“abs不能用作函数”(Group Class Project)

时间:2015-02-07 19:14:52

标签: c++ function compiler-errors

我和另外两个人正在为我们的C ++课程开发一个项目并且遇到了一个问题。该项目将在几天后到期,因此我将这个问题提交给任何人和每个人,以便在我们的截止日期之前解决。我们得到错误" abs不能用作函数"

请您查看我们的编码并给我们一些指导?谢谢!

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    double slope, yIntercept, xCoord, yCoord, yCoordCalc, yCalcLow;
    double yCalcHigh, yCalcDifference, abs;

    cout << "This program verifies that a selected point is on 
             a given line." << endl;
    cout << "All input values may be integer or floating-point." << endl;
    cout << "Enter slope: " << endl;
    cin >> slope;
    cout << "Enter y-intercept: " <<endl;
    cin >> yIntercept;
    cout << "Enter coordinates of the point: x y " << endl;
    cin >> xCoord >> yCoord;

    //calculate the Y coordinate;
    yCoordCalc = slope * xCoord + yIntercept;

    //calculate 2% above & below the yCoordCalc;
     yCalcLow = yCoordCalc * .98;
    yCalcHigh = yCoordCalc * 1.02;
    //calculate the difference
    yCalcDifference = yCalcHigh - yCalcLow;


    //Now use absolute value to check it (delta reference);
    if (abs((yCalcLow + yCalcDifference) - yCalcHigh) < yCoord)
    {
        cout << "The point is on the line.";
        return 1;
    }
    else
    {
        cout << "The point is NOT on the line.";
        return 0;
    }
}

1 个答案:

答案 0 :(得分:3)

你有一个变量

double abs

这是阴影函数

std::abs

1)重命名变量
2)Stop using using namespace std

我会推荐这些建议,而不只是一个。