dimanche 5 décembre 2021

C, if statement still executing even when false

I'm having problems with this part of my program. The idea is to find the length (double function) between two points (out of 4 for a rectangle) and then to find the area. I'm having problems though, mainly with my if(Sa >= S && S<=Sa) function. Even if I write Sa>S it still goes through every time, no matter if Sa is equal to 999999 or -1. I'm beginning to believe space is at fault here, for always sending a neutron to shoot a 0 to a 1.

Other parts of my code work. It reads from a file, but that works perfectly to a T. My code also finds the length no problem.

double RastiIlgi(int Ax, int Ay, int Bx, int By) 
{
    double x = (Bx-Ax);
    double y = (By-Ay);
    double ilgis =sqrt(x*x + y*y);
    return ilgis;
}

int main()
{
    int Ax, int Ay, int Bx, int By
    scanf("%d %d %d %d", Ax, Ay, Bx, By);
    double x, y, S, Sa=100;
    x=RastiIlgi(Ax, Ay, Bx, By);
    y=RastiIlgi(Ax, Ay, Dx, Dy);
    if(x==y)
    {
         x=RastiIlgi(Bx, By, Cx, Cy);
         y=RastiIlgi(Cx, Cy, Dx, Dy);
    }
    printf("%f %f \n", x, y);
    S=x*y;
    if(Sa >= S && S<=Sa)
    {
        Sa = S;
        printf("%f \n", S);
        printf("%f \n", Sa);
        
    }
}```

Aucun commentaire:

Enregistrer un commentaire