With this program I tried to make the computer guess the number I'm thinking. For example I choose x=50,y=50 and the program will try to guess it.My problem here is that the number the computer is guessing is out of the interval, for example the interval is between 1,100 and it will guess x=90 y=120. I have tried many ways to go around the code to try to understand why this is happening but I can't find the problem... If anyone knows why the computer isn't guessing in my interval it would be great!!
int main(void){
char tip[2];
int xmax=100,ymax=100;
int xmin=1,ymin=1;
int x,y,a=0;
while(true){
srand( (unsigned)time(NULL));
while (x>xmax && x<xmin && y>ymax && y<ymin){
x=rand()%xmax+xmin;
y=rand()%ymax+ymin;
}
printf("This is my try: x=%d e y=%d\nTip?\n",x,y);
scanf("%s", tip);
if((tip[0]=='E'||tip[0]=='W'||tip[0]=='N'|| tip[0]=='S')&& (tip[1]=='W'||tip[1]=='E'||tip[1]=='N'||tip[1]=='S'||tip[1]=='\0')){
if (tip[0]=='N'){
ymin=y;
}
else if(tip[0]=='S'){
ymax=y;
}
else if(tip[0]=='E'){
xmin=x;
}
else if(tip[0]=='W'){
xmax=x;
}
if(tip[1]=='W'){
xmax=x;
}
else if(tip[1]=='E'){
xmin=x;
}
else if(tip[1]=='N'){
ymin=y;
}
else{
ymax=y;
}
}
}
return 0;
}