C ++ error =“abs不能用作函数” (集团类项目) [英] C++ error = "abs cannot be used as a function" (Group Class Project)

查看:727
本文介绍了C ++ error =“abs不能用作函数” (集团类项目)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和另外两个人正在为我们的C ++类工作一个项目,并出现了一个问题。项目将在几天内,所以我把这个问题给任何人和每个人,以便在我们的到期日之前解决。我们得到的错误abs不能用作函数

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


推荐答案

有变量

double abs

这是阴影函数

std::abs

1)重命名您的变量

2)停止使用使用命名空间std

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

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

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

这篇关于C ++ error =“abs不能用作函数” (集团类项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆