Using a potentiometers for lift balancing

Hello everyone i am not a all pro programmer and i have been trying to create a lift balancer with potentiometers. the thing that i am having trouble is how do i tell the program to balance within a range a of 40, then to say if over or under that range change speed accordingly? I have an image of a part of the programming that I did.

Here is some Psuedo code that may help explain some logic

int direction
Setmotor(5,127*direction)
...........Rest of motors.........

if{leftPot-rightPot<=40){
    Change motors by ~15% accordingly
}

else if{rightPot-leftPot<=40){
    Change motors by ~15% accordingly
}

thank you for this, as this part of my program has been the most pondering to me.