Record and read SD card counters

hello there is a projem,
I activate a relay with the button, and when I press the button again, I close the relay. I have a problem with the program I share, for example, if I open and close the relay 10 times, I guess I have to give it a value 21. I think the counter counts the button as on and off.

The second problem is that I want to set the power on and off 100 times, but if the electricity is disconnected at the 20th turn, it starts from the beginning when I switch it on again. I bought a micro sd cart module but I have not been able to customize the program, thanks in advance to friends who can help

MGT.ino (1.17 KB)

?? ==>* for (int i = 21; i > tur_sayisi ; i++)*

if (digitalRead (role) == LOW)
{
digitalWrite(role , HIGH);
}
else
{
digitalWrite(role , LOW);
}

replace with ==> digitalWrite(role,!digitalRead (role)); // alternating

From the very start; it was not very clear what you want to obtain.
Tell HOW it should behave.. in details.