does not detect the function --abs- of the library --math.h--

0

Can you explain why I can not see the abs definition, because when I execute it I get a message saying

error: 'abs' not declared in this scope

note: I use the codeblocks compiler 13.12

#include<iostream>
#include<math.h>
using namespace std;

int main(){
    float a,b,c,d,e = 0,f,x,y;
    cout<<"numero de vertices : ";
    cin>>f;

    cin>>a>>b;
    x = a;
    y = b;

    for(int i = 0; i < f; i++){
        cin>>c>>d;
        x = x - c;
        y = y - d;
        x = abs(x);
        y = abs(y);
        e = e + sqrt(x*x + y*y);
        x = c;  // un arreglo en el codigo
        y = d;  // un arreglo en el codigo
    }
    x = x - a;
    y = y - b;
    x = abs(x);
    y = abs(y);
    e = e + sqrt(x*x+ y*y);

    cout<<e;
}

note: the code is to solve this exercise.

- Polygon--
Make a program that reads a sequence of 2D points (real pairs) that represent a polygon (the last point of the sequence is the same as the first), and determines the length of its perimeter.

font link

    
asked by bassily 25.05.2016 в 02:48
source

3 answers

0

Replaces

#include<math.h>

for

#include<cmath>

math.h belongs to the standard , you must use the libraries of the standard

answered by 26.05.2016 / 01:03
source
2

It worked perfectly for me once the errors indicated by rnd and remembered by Camilo .

You can [see it here] .

Other details to take into account:

Library types

The headers of

answered by 25.05.2016 в 09:24
0

They have already given you the answer, to include a library, use #, only that should work with you, but it does not matter if you change math.h by cmath (they are the same but the second is from c ++).

    
answered by 25.05.2016 в 07:16