Arduino to Arduino I2C and slave sends two variables to master

Here is my situation. I have two arduino boards a Uno (slave) Mega (master) connected via I2C. I need to send two different variables from the slave to the master. My problem is that when the slave sends the variables the master only receives the second variable. How can I send two different variables over I2C? Here is my current code:

//i2c Master(MEGA)
#include <Wire.h>

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  int reading = 0;
  
  int x;
  int y;
  
  Wire.beginTransmission(5);  //  Transmit to device #5
  Wire.write(byte(0x02));
  Wire.endTransmission();
  
  // Request reading from sensor
  Wire.requestFrom(5,1);
  
  //if(1<= Wire.available())  //If 1 byte was recieved
  x = Wire.read();
  Serial.println(x);
  delay(250);
  Wire.beginTransmission(5);  //  Transmit to device #5
  Wire.write(byte(0x10));
  Wire.endTransmission();
  
  // Request reading from sensor
  Wire.requestFrom(5,1);
  
  //if(1<= Wire.available())  //If 1 byte was recieved
  y = Wire.read();
  Serial.println(y);
  delay(250);
}

  /*
  while(Wire.available())
  {
    int x = Wire.read();
    Serial.print(x);
    
    int y = Wire.read();
  }
}
*/

void loop()
{
}
/*
*I2C_Slave (UNO)
*Monitors I2C requests and echoes these to the serial port
*/

#include <Wire.h>
int x;
int y;
int c;

const int address = 5;  //  The address to be used by the communicating devices

void setup()
{
  Wire.begin(address);  //  Join I2C bus using this address
  Wire.onRequest(requestEvent);  //  Register event to handle requests
  
  Wire.onReceive(receiveEvent);
x = 5;
y = 9;
}

void loop()
{
  delay(100);// Nothing here, all the work is done in receiveEvent
}

void receiveEvent(int howMany)
{
  while(Wire.available()>0)
  {
  int c = Wire.read();
  }
}


void requestEvent()
{
  if(c = byte(0x02))
  {
  Wire.write(x);
  }
  delay(250);
  if(c = byte(0x10))
  {
  Wire.write(y);
  }
}

When I run the two codes below my x variable gets over written with the y variable, so then I only get a y y when it is printed out on the serial monitor.

I found this code. I looks like it will work for me! I’m posting it just in case it might help someone else out.

/* 

Thanks to the work at http://www.bot-thoughts.com/2010/06/arduino-to-arduino-i2c.html I was able to create this demo.

*/

#include <Wire.h>
#define device 1

byte dataIn[3] = {
};
int command = 0;


void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  sendCommand(); 
  delay(1);
  command ++;
  if(command > 2)
  {
    command = 0; 
  }
}

void sendCommand()
{
  Serial.print("Sending command ");
  Serial.println(command);
  dataIn[0] = 0;
  dataIn[1] = 0;
  dataIn[2] = 0;
  switch(command)
  {
  case 0:
    readDataA();
    break;

  case 1:
    readDataB();
    break;

  case 2:
    sendData();
    break;

  default:
    break;
  } 
  printDataIn();
}

void readDataA()
{
  Wire.beginTransmission(device);
  Wire.write(0);
  Wire.endTransmission();
  int i = 0;
  delay(1);
  Wire.requestFrom(device, 3);
  while(Wire.available())    // slave may send less than requested
  { 
    byte c = Wire.read();
    dataIn[i] = c; 
    i ++;
  }

}


void readDataB()
{
  Wire.beginTransmission(device);
  Wire.write(1);
  Wire.endTransmission();
  int i = 0;
  delay(1);
  Wire.requestFrom(device, 3);
  while(Wire.available())
  { 
    byte b = Wire.read();
    dataIn[i] = b; 
    i ++;
  }

}

void sendData()
{
  Wire.beginTransmission(device);
  Wire.write(2);
  byte dataOut[3] = {
    200, 150, 100      };
  Wire.write(dataOut, 3);
  int result = Wire.endTransmission();
  if(result > 0)
 {
    Serial.print("Error in transmission");
  }
  else
  {
  int i = 0;
  delay(1);
  Wire.requestFrom(device, 3);
  while(Wire.available())    // slave may send less than requested
  { 
    byte b = Wire.read();
    dataIn[i] = b; 
    i ++;
  }
}
  
}

void printDataIn()
{
  Serial.println("Data in values are as follows:");
  Serial.print("[0] = ");
  Serial.println(int(dataIn[0]));
  Serial.print("[1] = ");
  Serial.println(int(dataIn[1])); 
  Serial.print("[2] = ");
  Serial.println(int(dataIn[2])); 
  Serial.println();
}
#include <Wire.h>

byte dataOut[3] = {};
byte dataIn[6] = {};
boolean dataReady;
boolean requestIn;
boolean receiveIn;
unsigned char reg;

void setup()
{
  Wire.begin(1);
  dataReady = false;
  Wire.onRequest(handleRequest);
  Wire.onReceive(handleReceive);
  digitalWrite(13, HIGH);
}

void loop()
{
  if(dataReady)
  {
    checkCommand(); 
    dataReady = false;
  }
}

void checkCommand()
{
  switch(dataIn[0])
  {
  case 0:
    dataOut[0] = 1;
    dataOut[1] = 2;
    dataOut[2] = 3;
    break;

  case 1:
    dataOut[0] = random(0, 255);
    dataOut[1] = random(0, 255);
    dataOut[2] = random(0, 255);
    break;

  case 2:
    dataOut[0] = dataIn[1];
    dataOut[1] = dataIn[2];
    dataOut[2] = dataIn[3];

  default:
    break;
  }
}

void handleReceive(int howMany)
{
  int i = 0;
  while(Wire.available())
  {
    byte b = Wire.read();
    dataIn[i] = b; 
    i ++;
  }
  dataReady = true;
}

void handleRequest()
{
  Wire.write(dataOut, 3);
}