Stuck in While loop!
You're masking your outer dvert variable (and potentially others that you want to keep) with local variables inside the loop:

  int dvert = avgtop - avgbot; // check the diffirence of up and down  


If you're just assigning a new value to an existing variable you do not want to declare a new variable!

Instead it should be just:

  dvert = avgtop - avgbot; // check the diffirence of up and down  


And the same for anything else inside the loop that you want to assign to a variable that you have created outside the loop.