Merlot
Merlot

Reputation: 21

C++ error = "abs cannot be used as a function" (Group Class Project)

Myself and two other people are working on a project for our C++ class and have come upon an issue. The project is due in a few days so I'm putting this question out to anyone and everyone in order to have it resolved before our due date. We are getting the error "abs cannot be used as a function"

Could you please review our coding and give us some guidance? Thanks!

#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;
    }
}

Upvotes: 0

Views: 846

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 117886

You have a variable

double abs

That is shadowing the function

std::abs

1) Rename your variable
2) Stop using using namespace std

I would recommend BOTH of those suggestions, not just one.

Upvotes: 3

Related Questions