Hi.. I am doing C programming on microsoft Visual C++. I want to prompt the user for coordinate again and again if the input coordinate doesn't meet the condition. But after I type in the coordinate, the program keeps on looping infinitely. Sorry for the super BEGiNNER question.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int x,y,invalid=1;
while (invalid)
{
printf("Please enter the coordinate of the ship:\n");
scanf(" %d %d", &x,&y);
invalid=((x>10 || x<0) &&(y<10 || y>25))?1:0;
}
}
I want to prompt the user again for coordinates if the user types a coordinate within this range
(x>10 || x<0) &&(y<10 || y>25)