Edit 2: What I was asked to do:
Your program should read the coordinates of a soccer ball on the field, and say whether it is in the field, whether it was on the side, whether it was in the bottom or if it is inside the goal. The field is a rectangle of 100x70m. The center of the coordinates is in the center of the field. The x coordinates of the field range from -50 to 50. The program should first read the x-coordinate and then the y-coordinate of the ball. Consider a line diagonally coming out of each corner of the field to decide whether the ball came from the side or the bottom. Consider the goal as a rectangle of 7,32 x 2,44m leaving each end of field in the middle of it. The only information printed by the program should be a line (ending with \ n), with one of the messages: "inside", "lateral", "background" or "goal".
Edit: Full Code:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
//Vinicius Rossato Piovesan, Code::Blocks 17.12
int main()
{
float x, y, a, b, c, d, e, f, g, h;
a=50;
b=-50;
c=35;
d=-35;
e=51.22;
f=-51.22;
g=3.66;
h=-3.66;
printf("Digite a coordenada de x (da bola): \n");
scanf("%f", &x);
printf("Digite a coordenada de y (da bola): \n");
scanf("%f", &y);
if(x<=a && x>=b && y<=c && y>=d)
printf("Dentro. \n");
else if (x>=a && x<=e && y>=h && y<=g || x<=b && x>=f && y<=g && y>=h)
printf("Gol. \n");
else if ((x>a || x<b) && (y<=c || y>=d))
printf("Fundo. \n");
else if (x-a >= y-c || x+b >= y+d)
printf("Fundo. \n");
else
printf("Lateral. \n");
return 0;
}
Good evening.
I made a post but it was confusing, and unfortunately I can not delete it.
I need to make the number assigned to X be in abs so that it is only positive, but I do not know how to assign it.
else if ((x>a || x<b) && y<=c && y>=d)
printf("Fundo. \n");
else if (x-a >= y-c || x+b >= y+d)
printf("Fundo. \n");
else
printf("Lateral. \n");
return 0;
}
Thank you.