combining programs

im trying to combine two programs that serve the same purpose of filling a bucket with water but with one of the outputs being the same in the two. how do i go about it ive tried but failed several times.

boolean stateBoth = false;
const int button1Pin = 2;// top float switch of fresh water
const int button2Pin = 3;// bottom of fresh water
const int relay1Pin = 10;// rodi tank / shutoff relay
const int relay2Pin = 11;// fresh water
// or is this A0 on a Arduino Uno ?

// If in the initial state, both the buttons are pressed, then the first if-statement
// in the loop() will become active and the relays will be turned on.
// Therefor no special code is needed to solve the initial state of the buttons.

void setup()
{
  pinMode(relay1Pin, OUTPUT); //shut off relay
  pinMode(relay2Pin, OUTPUT);// fresh water //
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
}

void loop()
{
 // if the two are both in the same state then and only then will the relays be turned on
  if (digitalRead(button1Pin) == HIGH && digitalRead(button2Pin) == HIGH && !stateBoth)
  {
    stateBoth = true;
    digitalWrite(relay1Pin, LOW);// turn on tank
    digitalWrite(relay2Pin, LOW);// turn on fresh water relay
  }
  else if (digitalRead(button1Pin) == LOW && digitalRead(button2Pin) == LOW && stateBoth)
  {
    stateBoth = false;
    digitalWrite(relay2Pin, HIGH);// turn off relays
  }
}

then the second code

const int button3Pin = 4;// top salt switch of fresh water
const int button4Pin = 5;// bottom of salt water
const int relay1Pin = 10;// rodi tank / shutoff relay
const int relay3Pin = 12;// fresh water
// or is this A0 on a Arduino Uno ?

// If in the initial state, both the buttons are pressed, then the first if-statement
// in the loop() will become active and the relays will be turned on.
// Therefor no special code is needed to solve the initial state of the buttons.

void setup()
{
  pinMode(relay1Pin, OUTPUT); //shut off relay
  pinMode(relay3Pin, OUTPUT);// fresh water //
  pinMode(button3Pin, INPUT);
  pinMode(button4Pin, INPUT);
}

void loop()
{
 // if the two are both in the same state then and only then will the relays be turned on
  if (digitalRead(button3Pin) == HIGH && digitalRead(button4Pin) == HIGH && !stateBoth)
  {
    stateBoth = true;
    digitalWrite(relay1Pin, LOW);// turn on tank
    digitalWrite(relay3Pin, LOW);// turn on fresh water relay
  }
  else if (digitalRead(button1Pin) == LOW && digitalRead(button2Pin) == LOW && stateBoth)
  {
    stateBoth = false;
     digitalWrite(relay1Pin, HIGH);// turn OFF tank
    digitalWrite(relay3Pin, HIGH);// turn off relays
  }
}

sorry the first program is

boolean stateBoth = false;
const int button1Pin = 2;// top float switch of fresh water
const int button2Pin = 3;// bottom of fresh water
const int relay1Pin = 10;// rodi tank / shutoff relay
const int relay2Pin = 11;// fresh water
// or is this A0 on a Arduino Uno ?

// If in the initial state, both the buttons are pressed, then the first if-statement
// in the loop() will become active and the relays will be turned on.
// Therefor no special code is needed to solve the initial state of the buttons.

void setup()
{
  pinMode(relay1Pin, OUTPUT); //shut off relay
  pinMode(relay2Pin, OUTPUT);// fresh water //
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
}

void loop()
{
 // if the two are both in the same state then and only then will the relays be turned on
  if (digitalRead(button1Pin) == HIGH && digitalRead(button2Pin) == HIGH && !stateBoth)
  {
    stateBoth = true;
    digitalWrite(relay1Pin, LOW);// turn on tank
    digitalWrite(relay2Pin, LOW);// turn on fresh water relay
  }
  else if (digitalRead(button1Pin) == LOW && digitalRead(button2Pin) == LOW && stateBoth)
  {
    stateBoth = false;
     digitalWrite(relay1Pin,HIGH);
    digitalWrite(relay2Pin, HIGH);// turn off relays
  }
}

What will your combined sketch do?

This Simple Merge Demo may give you some ideas.

...R