well lets see if my math doesn't fail me
to define such a thing the equation would be something along the lines of:
- 1<Y<3, -5<=X<=5
- Y<3/4X+1, 0<=X<=4
- Y<4/3X+1, -4<=X<=0
- Y<3X+1, -5<=X<=-4
- Y<1/3X+1, 4<=X<=5
This are a bunch of equations that basically set the area with this you can make a really ineffective if and else() we could use a bit of math and if you had asked me this like a year ago i would still have in mind the analitics class unfortunetely thats long gone, but i have one last card up my sleeve and thats wolfram alpha i putted up the equations it pasted the following(except the 1<Y<3 as that caused a small error)
(Y<3/4X+1, 0<=X<=4) and(Y<4/3X+1, -4<=X<=0) and (Y<3X+1, -5<=X<=-4) and (Y<1/3X+1, 4<=X<=5)
Welp unfortunately it outputted the same so were gonna go into the code now we just need to create a function i will try to find a better "formula compression" tomorrow
Also since you are new i will have to explain some things || is a logical or while && is a logical and this has to do with math i chose double instead of float because the problem is mostly a math problem so i chose some precision although the input is an int because im lazy ive already answered on how to protect the scanf from wrong input requests at Is there a way of limiting scanf in C?
so if you need this code to be well rounded and user proof read above
in C true is any number that is not zero meaning while(1) or while(133) make infinite loops since they will always be true
%d in the scanf are the format modifier to basically tell C "im waiting for an integer"
int IsItInside(double x, double y){
if (y>3 || y<1 ){// i dont need to "range" this since the its always like this
return 0;
}
if (y<(((3*x)/4)+1)&& x>=0 && x<=4){
return 1;
}
if (y<((4/(3*x))+1) && x>=-4 && x<=0){
return 1;
}
if (y<((3*x)+1) && x>=-5 && x<=-4){
return 1;
}
if (y<((1/3*x)+1) && x>=4 && x<=5){
return 1;
}
return 0;
}
int main(int argc, char const *argv[]){
int x=0, y=0;
printf("Enter x: ");
scanf ("%d", &x);
printf("Enter y: ");
scanf ("%d", &y);
if(IsItInside(x,y)){
printf("It is inside");
}else{
printf("It is outside");
}
return 0;
}