Problem with number range on an LCD

First of all, I am new to Arduino and this forum. I am a chef and I have no programming experience but I’m doing a lot of reading and learning.

I am working on a project which involves a number range constrained from 0-300 on a 16x2 LCD, and another range from 0-100, adjustable via buttons (up and down). The problem is that once the numbers get up to or over 100, and then I try to scroll back down, its puts the number in the wrong place, i.e. 101, 100, 990, 980, instead of 101, 100, 99, 98.

Any advice or help would be greatly appreciated.
I will post the code I have written, which works fine but any advice on how to improve it would also be greatly appreciated. Please bear in mind I only have about 3 weeks experience.

TechChef

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int up = 7;
int down = 8;
int alt = 6;
int mode = 9;
int lvl1 = 0;
int lvl2 = 0;
int lvl3 = 0;
int time1 = 0;
int time2 = 0;
int time3 = 0;
int vary = 0;
int cycle = 1;

int u1;                     // variable for reading the pin status
int u2;                    // variable for reading the delayed status
int uState;               // variable to hold the button state
int d1;
int d2;
int dState;
int a1;
int a2;
int aState;
int m1;
int m2;
int mState;

 void setup() {
  
 pinMode(up, INPUT);
 pinMode(down, INPUT);
 pinMode(alt, INPUT);
 pinMode(mode, INPUT);
  lcd.begin(16, 2);
  lcd.setCursor(3, 0);
  lcd.print("Moisture ");
  lcd.setCursor(15, 0);
  lcd.print("%");
  lcd.setCursor(3, 1);
  lcd.print("Water On ");
  lcd.setCursor(15, 1);
  lcd.print("s");
  uState=digitalRead(up);
  dState=digitalRead(down);
  aState=digitalRead(alt);
  mState=digitalRead(mode);
 }

 void loop() {
  time1 = constrain(time1, 0, 300);
  lvl1 = constrain(lvl1, 0, 100);
  time2 = constrain(time2, 0, 300);
  lvl2 = constrain(lvl2, 0, 100);
  time3 = constrain(time3, 0, 300);
  lvl3 = constrain(lvl3, 0, 100);
 m1=digitalRead(mode);
 delay(10);
 m2=digitalRead(mode);
 if (m1 == m2) {
  if (m1 != mState){
   if (m1 == LOW) {
    if (cycle == 1){
    cycle = 2;
    } else {
       if (cycle == 2){
       cycle = 3;
       } else {
          if (cycle == 3){
          cycle = 1;
        }
      }
    }
  }
   }
 }
 mState = m1;
   
      
 a1=digitalRead(alt);
 delay(10);
 a2=digitalRead(alt);
 if (a1 == a2) {
  if (a1 != aState){
   if (a1 == LOW) {
    if (vary == 0){
    vary = 1;
    } else {
       if (vary == 1){
       vary = 0;
      }
    }
  }
 }
 }
 aState = a1;
 
 if (cycle == 1){
  lcd.setCursor(0, 0);
  lcd.print("#1 ");
  lcd.setCursor(12, 0);
  lcd.print(lvl1);
  lcd.setCursor(0, 1);
  lcd.print("#1 ");
  lcd.setCursor(12, 1);
  lcd.print(time1);
  
 //up button controls time
  if (cycle == 1 && vary ==0) {
   u1=digitalRead(up); 
   delay(10);
   u2=digitalRead(up);
 if (u1 == u2) {
  if (u1 != uState) {
   if (u1 == LOW) {
   time1 += 15;
      }
    }
 }
 uState = u1;

  //down button controls time
 d1=digitalRead(down); 
 delay(10);
 d2=digitalRead(down);
 if (d1 == d2) {
  if (d1 != dState) {
   if (d1 == LOW) {
   time1 -= 15;
      }
    }
 }
 dState = d1;
  }
  
  
 if (cycle == 1 && vary ==1) {
  //up button controls lvl
  u1=digitalRead(up); 
 delay(10);
 u2=digitalRead(up);
 if (u1 == u2) {
  if (u1 != uState) {
   if (u1 == LOW) {
   lvl1 += 5;
      }
    }
 }
 uState = u1;

 //down button controls lvl
 d1=digitalRead(down); 
 delay(10);
 d2=digitalRead(down);
 if (d1 == d2) {
  if (d1 != dState) {
   if (d1 == LOW) {
   lvl1 -= 5;
      }
    }
 }
 dState = d1;
 }
 }
 if (cycle == 2){
  lcd.setCursor(0, 0);
  lcd.print("#2 ");
  lcd.setCursor(12, 0);
  lcd.print(lvl2);
  lcd.setCursor(0, 1);
  lcd.print("#2 ");
  lcd.setCursor(12, 1);
  lcd.print(time2);
 
 //up button controls time
 if (cycle == 2 && vary ==0) {
 u1=digitalRead(up); 
 delay(10);
 u2=digitalRead(up);
 if (u1 == u2) {
  if (u1 != uState) {
   if (u1 == LOW) {
   time2 += 15;
      }
    }
 }
 uState = u1;

 //down button controls time
 d1=digitalRead(down); 
 delay(10);
 d2=digitalRead(down);
 if (d1 == d2) {
  if (d1 != dState) {
   if (d1 == LOW) {
   time2 -= 15;
      }
    }
 }
 dState = d1;

  }
 if (cycle == 2 && vary ==1) {
 //up button controls lvl
 u1=digitalRead(up); 
 delay(10);
 u2=digitalRead(up);
 if (u1 == u2) {
  if (u1 != uState) {
   if (u1 == LOW) {
   lvl2 += 5;
      }
    }
 }
 uState = u1;

 //down button controls lvl
 d1=digitalRead(down); 
 delay(10);
 d2=digitalRead(down);
 if (d1 == d2) {
  if (d1 != dState) {
   if (d1 == LOW) {
   lvl2 -= 5;
      }
    }
 }
 dState = d1;

 }
 }
 if (cycle == 3){
  lcd.setCursor(0, 0);
  lcd.print("#3 ");
  lcd.setCursor(12, 0);
  lcd.print(lvl3);
  lcd.setCursor(0, 1);
  lcd.print("#3 ");
  lcd.setCursor(12, 1);
  lcd.print(time3);

 //up button controls time
 if (cycle == 3 && vary ==0) {
 u1=digitalRead(up); 
 delay(10);
 u2=digitalRead(up);
 if (u1 == u2) {
  if (u1 != uState) {
   if (u1 == LOW) {
   time3 += 15;
      }
    }
 }
 uState = u1;

 //down button controls time
 d1=digitalRead(down); 
 delay(10);
 d2=digitalRead(down);
 if (d1 == d2) {
  if (d1 != dState) {
   if (d1 == LOW) {
   time3 -= 15;
      }
    }
 }
 dState = d1;

  }
 if (cycle == 3 && vary ==1) {
 //up button controls lvl
 u1=digitalRead(up); 
 delay(10);
 u2=digitalRead(up);
 if (u1 == u2) {
  if (u1 != uState) {
   if (u1 == LOW) {
   lvl3 += 5;
      }
    }
 }
 uState = u1;

 //down button controls lvl
 d1=digitalRead(down); 
 delay(10);
 d2=digitalRead(down);
 if (d1 == d2) {
  if (d1 != dState) {
   if (d1 == LOW) {
   lvl3 -= 5;
      }
    }
 }
 dState = d1;
 }
 }
 }

Please bear in mind I only have about 3 weeks experience.

And none of them searching how other people have addressed this issue.

The simplest solution is to print two spaces after each value. "100 " will be completely obscured by "99 " or "4 ".

Thanks for the quick reply, it fixed my problem. I thought I had done a lot of research on this, must have missed that somewhere. You really don't make a new person feel welcome to ask a question but I really appreciate the information.

TechChef