Guidance to make my robot work

I am trying to create a kind of robot where you store the movements of the robot using the buttons provided(forward,behind,left or right). There are five buttons in all. Four for the movement and one for making the robot move. I want the movements(the key pressed) to be stored in an array and later use it when the run switch is pressed. This is my code

const int motora1 = 8;
const int motora2 = 7;
const int motorb1 = 4;
const int motorb2 = 2;
const int switch1 = 3;
const int switch2 = 5;

const int switch3 = 6;
const int switch4 = 9;
const int runswi = 10;

int swiread1 = 0;
int swiread2 = 0;
int swiread3 = 0;
int swiread4 = 0;
int runread = 0;
int i=0,k=0;
int p[400];

void setup()
{
pinMode(motora1, OUTPUT);
pinMode(motora2, OUTPUT);
pinMode(motorb1, OUTPUT);
pinMode(motorb2, OUTPUT);
pinMode(switch1, INPUT);
pinMode(switch2, INPUT);
pinMode(switch3, INPUT);
pinMode(switch4, INPUT);
pinMode(runswi, INPUT);
Serial.begin(9600);
}

void loop()
{
swiread1 = digitalRead(switch1); //forward
swiread2 = digitalRead(switch2); // backward
swiread3 = digitalRead(switch3);// right
swiread4 = digitalRead(switch4);// left
runread = digitalRead(runswi);
if(runread!=HIGH)
{
if(swiread1 == HIGH)
{
p*=1;*

_ Serial.print(p*);_
_
delay(400);*_

* }*
* if(swiread2 == HIGH)*
* {*
_ p*=2;*_

_ Serial.print(p*);
delay(400);*_

* }*
* if(swiread3 == HIGH)*
* {*
_ p*=3;
Serial.print(p);
delay(400);*_

* }*
* if(swiread4 == HIGH)*
* {*
_ p*=4;*_

_ Serial.print(p*);
delay(400);
}
}
else*

* {
readata();
k=i;
}
}*_

* void readata()*
* {*
* for(i=0;i<k;i++)*
* {*
_ Serial.print(p*);
}
for(i=0;i<k;i++)
{
switch(p)
{
case 1: // forward*

* digitalWrite(motora1, HIGH);
digitalWrite(motora2, LOW);
digitalWrite(motorb1, LOW);
digitalWrite(motorb2, HIGH);
delay(1000);
break;*_

* case 2: // backward*
* digitalWrite(motora1, LOW);*
* digitalWrite(motora2, HIGH);*
* digitalWrite(motorb1, HIGH);*
* digitalWrite(motorb2, LOW);*
* delay(1000);*
* break;*

* case 3: // right*
* digitalWrite(motora1, HIGH);*
* digitalWrite(motora2, LOW);*
* digitalWrite(motorb1, HIGH);*
* digitalWrite(motorb2, LOW);*
* delay(3200);*
* break;*

* case 4: // left*
* digitalWrite(motora1, LOW);*
* digitalWrite(motora2, HIGH);*
* digitalWrite(motorb1, LOW);*
* digitalWrite(motorb2, HIGH);*
* delay(3200);*
* break;*

* }*
* }*
}

Is there a question?

7 below has what you need.

http://forum.arduino.cc/index.php/topic,148850.0.html

If you want help with your problem, you need to explain what the problem is.

Just to get you started, it seems to me that you have far too much data that should be local held in global variables. Your array and count variables need to be global but I don't see that anything else does. Also, give your variables meaningful names.

swiread1 = digitalRead(switch1); //forward
int forwardState = digitalRead(ForwardPin);

What you could do is assign each button a number (1-4) and every time a button is pressed, it stores the number in an array. Now for this to work properly, you will need to use Case statements, so case 1 would be forward movement, case 2 is reverse movement, 3 is left, 4 is right. You may want a default case to stop the robot too.

Now when the fifth button is pressed, it will go through the sequence. You may want to set a fail safe limit, so if you press too many combinations, the code knows not to overflow the array, and to then start the sequence. Another thing make you also keep track of the number of combinations you enter, this way, you can use a simple FOR/WHILE loop to go through the sequence.