if( ( abs(ballposition.x-balltarget.x) + abs(ballposition.y-balltarget.y) ) < (ballspeed * 2) )
{
balltarget.x = rand() % SCREEN_WIDTH;
balltarget.y = rand() % SCREEN_HEIGHT;
}
But as it seems to be about a ball, I feel inclined to suggest that you just use an actual velocity vector,
the root of the squares of dX and dY added. (Or don't do the root but work in squared units, if you can/want to.)
Even better, you could use a 2d vector struct
struct 2dmotionvector
{
float dx;
float dy;
float len;
float angle;
}
To define your velocity, and work with that instead of having only independent x and y speeds to deal with.-You can use len and angle primarily, and then set dx and dy if you need it in later statements.
(What if you apply spin to the ball, or it bounces off a surface? Way easier with 2d vector math on composite types in my opinion)