In this code, two inverted String to int variables must be added, but adding any numbers will result in -18432

  arduino, arduino-c++, arduino-ide, c++

The task is to make a keyboard using an LCD display and a matrix keyboard, so far I have written the code only for adding numbers, but it gives out for any values ​​of a and b -18432, which is the problem I just can’t understand and find.
I removed half of the code, which is not related to the question.
I have been programming and learning arduino c not so long ago, don’t scold me):(

    int a;
    int b;
    char znak;
    int8_t k = 0;
    char customKey;
    
    void loop() {
      FirstNum();
      SecondNum();
      int otvet;
      if(znak == '+'){
        otvet = a+b;
      }
      lcd.clear();
      lcd.print(otvet);
    }
     
    void FirstNum(){
      String FirstNum;
      String FirstNum1;
      for(;;){
       customKey = customKeypad.getKey();
         if(customKey){
            if(customKey == 'A' || customKey == 'B' || customKey == 'C' || customKey == 'D')
        {
          znak = customKey;
          switch(customKey){
           case 'A': a = FirstNum1.toInt();
                     lcd.setCursor(15, 0);
                     lcd.print("+"); return;
          }
         }  
         FirstNum = String(customKey);
         FirstNum1;
         FirstNum1 += FirstNum;
         lcd.setCursor(k, 0);
         lcd.print(customKey);
         k++;

    
    void SecondNum(){
      String SecondNum;
      String SecondNum1;
      customKey = '{$content}';
      k = 0;
        for(;;){
       customKey = customKeypad.getKey();
          if(customKey == '#'){
           lcd.setCursor(15, 1);
           lcd.print("=");
           b = SecondNum1.toInt();;
           return; 
          }
         if(customKey){
         String SecondNum = String(customKey);
         String SecondNum1;
         SecondNum1 += SecondNum;
         lcd.setCursor(k, 1);
         lcd.print(customKey);
         k++;
    

Source: Windows Questions C++

One Reply to “In this code, two inverted String to int variables must be added, but adding any numbers will result in -18432”

LEAVE A COMMENT