Hey! Did not find any topic about this more than using if statment.
I want to declare a middle position and that would be between 0 and 3000. How do I write this? Should I use a variable insted?
int top_position = 0;
int bottom_position = 3000;
int middle_position = ??
int bottom_position = 3000;
int middle_position = (bottom_position - top_position)/2;
That should be (bottom_position + top_position) / 2.
If you want a version that works correctly in all cases, even when overflow could occur, you have to be a bit more careful, see https://www.youtube.com/watch?v=sBtAGxBh-XI.