jung
jung

Reputation: 35

Error invalid operands to binary & (have 'int **' and 'int *')

I'm trying to figure out the length of the three sides of the triangle, then sort them in order, and see if the triangle is formed. I must use struct, but this error appears. my compiler is Dev C++ and the limitation of this problem is three point of triangle should be Integer. and tag name of struct should 'Point'. I need your assisstance with this.

error of this code is "invalid operands to binary & (have 'int **' and 'int *')"

#include <stdio.h>
#include <math.h> 

typedef struct {
    int x;
    int y;
} Point;

int main()
{
    Point p1, p2, p3;    
    
    int temp;

    printf("please input first Point\n");
    scanf("%lf %lf", &p1.x &p1.y);

    printf("second Point\n");
    scanf("%lf %lf", &p2.x &p2.y);
    
    printf("Third Point\n");
    scanf("%lf %lf", &p3.x &p3.y); 

    int aX = p2.x - p1.x;    
    int aY = p2.y - p1.y;    

    int a = sqrt(pow(aX, 2) + pow(aY, 2));
    
    int bX = p3.x - p2.x;    
    int bY = p3.y - p2.y;   

    int b = sqrt(pow(bX, 2) + pow(bY, 2));
    
    int cX = p3.x - p1.x;   
    int cY = p3.y - p1.y;   

    int c = sqrt(pow(cX, 2) + pow(cY, 2));
    
    if (a >= b){
        temp = b;
        b = a;
        a = temp;
    }
    if (b >= c){
        temp = c;
        c = b;
        b = temp;
    }
    if (a >= b){
        temp = b;
        b = a;
        a = temp;
    }
    
    if(c< a + a){
        printf("ture");
    }
    else{printf("false");}

    return 0;
}

what is a problem?

Upvotes: 1

Views: 4599

Answers (2)

Avishka Dambawinna
Avishka Dambawinna

Reputation: 1215

Use of binary & operator (bitwise AND) with the arguments &p1.x and p1.y is also wrong. I recommend you to refer more about Input-output operations.

I fixed your code, only the code not the theory.

#include <stdio.h>
#include <math.h> 

typedef struct Triangles{
    int x;
    int y;
} ;

int main()
{
    struct Triangles p1;
    struct Triangles p2;
    struct Triangles p3;   

    int temp;

    printf("please input first Point\n");
    scanf("%d %d", &p1.x ,&p1.y);

    printf("second Point\n");
    scanf("%d %d", &p2.x ,&p2.y);

    printf("Third Point\n");
    scanf("%d %d", &p3.x ,&p3.y); 

    int aX = p2.x - p1.x;    
    int aY = p2.y - p1.y;    

    int a = sqrt(pow(aX, 2) + pow(aY, 2));

    int bX = p3.x - p2.x;    
    int bY = p3.y - p2.y;   

    int b = sqrt(pow(bX, 2) + pow(bY, 2));

    int cX = p3.x - p1.x;   
    int cY = p3.y - p1.y;   

    int c = sqrt(pow(cX, 2) + pow(cY, 2));

    if (a >= b){
        temp = b;
        b = a;
        a = temp;
    }
    if (b >= c){
        temp = c;
        c = b;
        b = temp;
    }
    if (a >= b){
        temp = b;
        b = a;
        a = temp;
    }

    if(c< a + a){
        printf("ture");
    }
    else{printf("false");}

    return 0;
}

Forgot to mention the format specifier %lf(used for double) is wrong it must be %d for **int*.*Cheers!

Upvotes: 1

ruakh
ruakh

Reputation: 183300

The error message is because the compiler thinks you're trying to use the binary & operator (bitwise AND) with the arguments &p1.x and p1.y, which doesn't make sense.

That, in turn, is because you're missing commas between certain function arguments; for example, this:

    scanf("%lf %lf", &p1.x &p1.y);

should be this:

    scanf("%d %d", &p1.x, &p1.y);

(Note that I've also corrected the format specifier — it's %d, not %lf, for an int.)

Upvotes: 2

Related Questions