0

I'm working in implementing an elevator
the project is about a building which has 2 elevators working together

I wrote a function (switch) to determine the direction of each elevator and that's my code

if( E1.loc == E2.loc )
				{
					if(upup1!=0 && dndn1!=0)
					{
						E1.status='u';
						E2.status='d';
					}
					else
						if(upup1!=0 && dndn1==0)
						{
							E1.status='u';
							if(upup1>1)
							{
								E2.status='u';
							}
								
				}

upup1,dndn1,updn1,dnup1 are integers for E1
upup2,dndn2,updn2,dnup2 are integers for E2


when the 2 elevators are in the same location
I reached the condition of (upup1!=0 && dndn1==0)
E1 goes up
but the next condition (upup1>1) don't make E2 goes up
although I've initiallized upup1=2

Edited by Hatem Faheem: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by dwks
0

Well, first of all, the whole if-statement only executes if E1.loc == E2.loc , which I'm assuming means that the elevators are at the same position. I'm not sure whether this is what you want.

Next notice that your code has some conditions when it does nothing. Suppose, for example, that upup1=-1 and dndn1=0. Then neither E1.status nor E2.status will be assigned a value. There are numerous other cases.

Perhaps you could start out by explaining what those upup1 etc variables are for, and why they're not inside the E1 and E2 structures.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.