Elevator Logic

I'm writting a program that would simulate the logic of an elevator. I was doing well, but then when I made some while loops to simulate the delays of the elevator opening it's doors and moving floors I ran into a problem. Although the syntax is right, the program does not seem to be reading the loops and I am not getting the delays. Here is the part of the code that is doing this. If someone could show me how to fix this that would be great.

//Pick Up System

if(Up1 == pushed){
cout << "Elevator has arrived on Floor One! Door opening!" << endl;

while(x < 200000000) {
cout << "Test" << endl;
x++;
}
cout << "Door has opened." << endl;
CurrentFloor = 1;

}

//elevator rising
cout << "Elevator rising to next qued level." << endl;

while(x < 200000000){
cout << "Test" << endl;
x++;
}

if(Up2 == pushed){
cout << "Elevator has arrived on Floor Two! Door opening!" << endl;

while(x < 200000000){
cout << "Test" << endl;
x++;
}
cout << "Door has opened." << endl;
CurrentFloor = 2;

}

cout << "Elevator rising to next qued level." << endl;

while(x < 200000000){
cout << "TEST" << endl;
x++;
}

if(Up3 == pushed){
cout << "Elevator has arrived on Floor Three! Door opening!" << endl;

while(x < 200000000){
cout << "TEST" << endl;
x++;
}

cout << "Door has opened." << endl;
CurrentFloor = 3;


}


}
It is no clear what is the initial value of x in each loop and what type x has.
I could put in the full code, I just thought this would be easier, sorry. Here is the full code, hopefully you can see all the variables a bit better.

#include <iostream>

using namespace std;

int main()
{
//stores that button was pushed.
int pushed = 1;

//Up buttons outside the elevator
int Up1;
int Up2;
int Up3;
int Up4;
int Up5;

//Keep track of current floor
int CurrentFloor;

//to end all loops
int x;

//Simulate people calling elevator

//check floor 1
cout << "If floor one has someone on it, press one. If not, press 0." << endl;
cin >> Up1;

if(Up1 == pushed){
cout << "Floor one has been qued!" << endl;
}

//check floor 2.
cout << "If floor two has someone waiting, press one. If not, zero." << endl;

//did someone call on floor 2?
cin >> Up2;
// If so...
if(Up2 == pushed){

cout << "Floor two has been qued." << endl;

}
//check F3
cout << "If floor 3 has someone waiting press one. If not, press 0." << endl;
cin >> Up3;

if(Up3 == pushed){
cout << "Floor three has been qued" << endl;

}

//check F4
cout << "If someone is on Floor 4 press one. If not press 0" << endl;
cin >> Up4;

if(Up4 == pushed){
cout << "Floor 4 has been qued!" << endl;
}

//check F5
cout << "If someone is on Floor 5, press one. If not press 0." << endl;
cin >> Up5;

if(Up5 == pushed){
cout << "Floor 5 has been qued!" << endl;
}


//Pick Up System

if(Up1 == pushed){
cout << "Elevator has arrived on Floor One! Door opening!" << endl;

while(x < 200000000) {
cout << "Test" << endl;
x++;
}
cout << "Door has opened." << endl;
CurrentFloor = 1;

}

//elevator rising
cout << "Elevator rising to next qued level." << endl;

while(x < 200000000){
cout << "Test" << endl;
x++;
}

if(Up2 == pushed){
cout << "Elevator has arrived on Floor Two! Door opening!" << endl;

while(x < 200000000){
cout << "Test" << endl;
x++;
}
cout << "Door has opened." << endl;
CurrentFloor = 2;

}

cout << "Elevator rising to next qued level." << endl;

while(x < 200000000){
cout << "TEST" << endl;
x++;
}

if(Up3 == pushed){
cout << "Elevator has arrived on Floor Three! Door opening!" << endl;

while(x < 200000000){
cout << "TEST" << endl;
x++;
}

cout << "Door has opened." << endl;
CurrentFloor = 3;


}


}
You are not assigning any initial value to variable x.
Wow, that was really obvious. Thank you. I feel kind of stupid now. -_- Oh well, thank you Vlad!
Just as a reminder can you use code tags to make your code more readable? When you copy and paste your code into the post box, go under format on your right and click on the two brackets the first box.
Ok, I will next time, thank you.
Topic archived. No new replies allowed.