Simulating a PLC ladder diagram on arduino

sorry for my last code. i have try the code, i can compile well but cant be execute according to the principle that talk before.
this is the one that work after i have spend time making it and testing it to be working well.

this is just an example:

/* 
 trying to set arduino latch funtion 

 connect pin 2 to a momentary push botton and the other leg to ground
pin2 -----./.----gnd
    ./. is a momentary switch
    repeat connection on pin3
    since most arduino have a LED connected to pin 13, i will use this to varify the code
*/
boolean result = LOW;
void setup()
{
  pinMode(2,INPUT); //setting pin 2 as input
  digitalWrite(2,HIGH);// activating pin 2 internal pull up
  pinMode(3,INPUT);// setting pin 3 as input 
  digitalWrite(3,HIGH);//activating pin 3 internal pull up
  pinMode(13, HIGH);// setting pin 13 as output
}

void loop()
{
  int Set = !digitalRead(2);
  int Reset =!digitalRead(3);
  int K=latch(Set,Reset);
  digitalWrite(13,K);
}


int latch(boolean s, boolean r)
{
  if ( (s== HIGH || result == HIGH) && r==LOW)
  { 
    result = HIGH;
   }
  if (r == HIGH)
  {
    result =LOW;
  }
 return result;
}