Turn on a LED and asign an adding up variable

Hello everyone! I am a newbie in the forum and in Arduino world and I need some help in a script I already did that works ok but have a problem that I couldn’t figure it out how to fix it. I have 2 buttons: the first one create a random number that keeps adding value in a variable called SUM until reach 20 and stops (everything is working fine here); the second button turn On a LED and put a variable of -10 everytime the LED is On. The problem here is that I want to substract -10 to the SUM variable everytime the button is pushed however, I am having problems because if I push the 1st button the SUM variable keeps substracting -10 in a loop instead of just subtracting -10 only when the botton is pushed.

Hope you can help me with this also, is there a better way to simplify my code?
Thank you a lot fo the advise!

Cheers!
Hector

This is the code:

#define PIN_BOTON_A 2
int pulsos_a = 0;
boolean anterior_a;
int randNumber;
int sum;

// --------------------------------------------------------------------------- boton add up
int ledPin = 13; // choose the pin for the LED
int switchPin =3; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int previousState = 0;
int sumf=0;
// --------------------------------------------------------------------------- boton add up

void setup() {
  Serial.begin(9600);
  randomSeed(analogRead(0));
  pinMode(PIN_BOTON_A, INPUT_PULLUP);
  anterior_a = digitalRead(PIN_BOTON_A);

pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(switchPin, INPUT); // declare pushbutton as input
}

void loop() 
{
boolean estado_a = digitalRead(PIN_BOTON_A);
randNumber = random(int(11));

//--------------------------------- LED-------------------
val = digitalRead(switchPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, HIGH); // turn LED on
currentState = 1;
}
else {
digitalWrite(ledPin, LOW); // turn LED off
currentState = 0;
}
if(currentState != previousState){
if(currentState == 1){
counter = counter + 1;
sumf=-10;
Serial.print(counter);
Serial.print("-------- suma= ");
Serial.println(sumf);
}
}
previousState = currentState;
delay(15);
//--------------------------------- LED-------------------
    
  if (anterior_a != estado_a) 
  {
      if (estado_a == LOW) 
     {

//-------------------------------------------------------------botton pushed ------------------------------
 if (sum<20)
 {     
          if (randNumber == 1) 
          {
            Serial.print(randNumber);
            Serial.print(" ------------ ");
            sum = sum + 2 + sumf;
            Serial.print("------- 2 ----- suma= ");
            Serial.println(sum);

           }
           else
                {
                if (randNumber == 5) 
                {
            Serial.print(randNumber);
            Serial.print(" ------------ ");
                  sum = sum + 5+ sumf;
                  Serial.print("------ 5 ------ suma= ");
                  Serial.println(sum);

                 }
                 else
                     {
                     if (randNumber == 10) 
                     {
              Serial.print(randNumber);
              Serial.print(" ------------ ");
                     sum = sum + 7+ sumf;
                     Serial.print("------ 7 ------ suma= ");
                     Serial.println(sum);

                     }
                     else
                         {
                         Serial.println(randNumber);
                         }
                      }
                    }
        
 }
 
//-------------------------------------------------------------botton pushed------------------------------
        }
  }

  anterior_a = estado_a;
  delay(15);
}

if I push the 1st button the SUM variable keeps substracting -10 in a loop instead of just subtracting -10 only when the botton is pushed.

You need to detect when the button becomes pressed rather than when it is pressed

Look at the StateChangeDetection example in the IDE to see how to do it.