Making a calculator using an Arduino

Updated :

I got the keyboard working better by using 74HC14. But a few "double entry" and a few "not reading right". In that case, I will use the LM339 to take care of the keypad "bad contact". Just a lots of breadboarding.

I just finish coding the calculator program. So far, The "Add" section is not working right. I may need some help. The rest is working fine. The "Clear" section is working fine. I will double check the "keynumber" section. Look it is working fine, but I will double check it.

I may re-code the "add" section. Instead of extracting the thousands, hundrens, tens, etc, and use a long variable, I will try the method use when we where in Grade 3. How to add a number.

Any help from you guys will be nice.

Here the Add section:

// Check for the "Add / Equal" button
    if ( ( keynumber == 0x0B ) && ( over_flow == 0) )
    {      
      the_number= 0;
      for (int i=0;i<8;i++)
      {
        temp_number = long(digit_number[i]) * power_of_ten[i];
        the_number = the_number + temp_number;       
      }  
      add_number = add_number + the_number;
      if (add_number <= 99999999)
      {
        for (int i=7;i>=0;i--)
        {
          digit_number[i] = byte(add_number / power_of_ten[i]);
          add_number = add_number - (long(digit_number[i]) * power_of_ten[i]); 
          display_data[i] = word ( ( i + 1) , digit_number[i] );        
        }
        for (int i=7;i>0;i++)
        {
          if ( digit_number[i] == 0 )
          {
             display_data[i] = word ( ( i + 1 ), 0x0F );
          }
          else 
          {
            break;
          }   
        }
        
        display_the_numbers();
        add_flag = 1;
        keystate = 0;
      }
      else
      {
        // Over Flow
        over_flow = 1;
        digit_number[0] = 0;
        display_data[0] = 0x010B;
        for ( int i=1;i<8;i++)
        {
           digit_number[i] = 0;
           display_data[i] = word( (i+1), 0x0F );               
        }      
        keystate = 0;      
        display_the_numbers();           
      }