Stuck with 7 segment and 4511 decoder

I've managed to get 2 7 segment displays working with 2 4511 decoders and can display numbers up to 99.

I want to add a third display and read numbers up to 150 and display them.

I cant for the life of me work out how to pick out the 100's and write to the 3rd display.... As you can guess I am new to all this.......

// the start of the BCD pins used for ABCD must be sequential
int BCDStart = 43;

// the start of the common pins - must be sequential
int commonStart = 47;

// this code can use either polarity of display.
// true if common is high when ON, otherwise false. Using common cathode = false
boolean commonHigh = false;

// the analog input for the potentiometer 
int analogIn = A4;


void setup() {
  // Enable all bcd outputs, 
  // set them to OFF 
  for(int i=0;i<4;++i) {
    pinMode(BCDStart + i, OUTPUT);// set each binary pin to be an output.
    digitalWrite(BCDStart + i, commonHigh?1:0);// If commonHigh is true (its false) set all pins to 1 else set to 0. Common cathode needs 0 (1 fires segment).
  }
  
  // Setup all the common pins, initially OFF.
  for(int i=0;i<3;++i) {
    pinMode(commonStart + i, OUTPUT);// set each LED common pin to be an output.
    digitalWrite(commonStart + i, commonHigh?0:1); //If commonHigh is true (its false) set to 0 else set to 1. Common cathode needs 1 (0 turns on display).
  }
   Serial.begin(9600);
}

void loop() {
  // read the analog input voltage 
  int amount = analogRead(analogIn)/7.86; // scaled at 150
  Serial.println (amount);
  
  for(int i=(2-1);i>=0;--i) {
    // find the current digit, which is in the low 4 bits. first pass is right display on, second pass swithches to left display.
    int digit = amount % 10;
 Serial.println (digit);   
    // and write out the representation of the voltage
    writeDigitToDisplay(digit);// first send remainder to function then 2nd pass send 10's to function
    
    // enable the correct digit for display
    digitalWrite(commonStart + i, commonHigh?1:0);//writes each returned bit of remainder to right display. 
    
    // short delay between changes.
    delay(1);
    // Turn off the correct digit for display
    digitalWrite(commonStart + i, commonHigh?0:1);
    
    // get the next digit.
    amount = amount / 10;// finds 10's value and rerun For to initiate middle display
   // Serial.println (amount);
   delay(1);
    // Turn off the correct digit for display
    digitalWrite(commonStart + i, commonHigh?0:1);
       
  }
}

// Now we define the bits that are on and off
// for ABCD output, These are used in the
// function below to generate the BCD for the 4511.
int dig[10] = {

          0b0000,//0
          0b0001,//1
          0b0010,//2
          0b0011,//3
          0b0100,//4
          0b0101,//5
          0b0110,//6
          0b0111,//7
          0b1000,//8
          0b1001,//9
          
};

void writeDigitToDisplay(int digit) {
  
  // iterate through each bit
  for(int i=0;i<4;++i) {
    // isolate the current bit in the loop.
    int currentBit = (1<<(i)); //shifts binary 0001 by 3-i. CurrentBit is 4 new combinations (as i changes)or reverse LSB read as (1<<(i))
   
    // check if the bit is on, and invert for
    // commonhigh if needed.
    int bitOn = (currentBit&digit)!=0;//if currentBit & digit then 3-1 is 1
    if(commonHigh) {//is false
      bitOn = !bitOn;//so bitOn stays at 1
    }
    
    // and lastly set the bit
    digitalWrite(BCDStart+i, bitOn); //writes bitOn to each BCD pin
    Serial.println (bitOn);
    
  }
}

I think I have fixed it. The code actually works but I had the common start pins for the led's mixed up!!

Last question. Is there a simple way to blank the leading 0 when the display is reading less than 100?

@kpg: Last question. Is there a simple way to blank the leading 0 when the display is reading less than 100?

Look at the data sheet for the 4511 decoder. pin 4 is labeled /BL and when pulled low it will turn off the segment drivers. So, for the hundreds position if the value is 0 then pull pin 4 low.