0
Edit 2: What I was asked to do:
Your program must read the coordinates of a football over the field, and tell if it is inside the field, if it has gone out the side, if it has gone out the back 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 read first the x coordinate and then the y coordinate of the ball. Consider a diagonal line coming out of each corner of the field, to decide whether the ball went out sideways or down the bottom. Consider the goal as a rectangle of 7.32 x 2.44m coming out of each end of the field, in the middle of it. The only information printed by the program should be a line (terminated by n), with one of the messages: "inside", "side", "bottom" 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 night.
I did a post but got confused, and unfortunately I can’t delete.
I need to make the number assigned to X be in abs so it’s only positive, but I don’t know how to assign.
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;
}
Grateful.
convert the
x
positive, if negative? That’s it?– Fábio Morais
Yes, that would be it.
– vinicius
When I assign to the x -75 and to the y 50 (should give the result of FUND), it is result of lateral, as if not read some of the numbers "right"
– vinicius
Link to previous question: https://answall.com/q/326300/132
– Victor Stafusa