Queue - Store simulation , customer waiting time issue

I am trying to build a queue of customers in a store. all the variables are printing the appropriate values but the waitingTime one. I have been working on this for a while and still can't figure it out. Can someone help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  void CreateCustomer (int time)
{
	int totalCustomersInLineA = 0;
	int totalCustomersInLineB = 0;
	int wait = 0;
	struct customer *new_customer;	 
		
	struct Queue* queueA = createQueue(1000);
   struct Queue* queueB = createQueue(1000);
	  
   new_customer = (struct customer*)malloc(sizeof(struct customer));
   new_customer->arrival_time = time;
   new_customer->size_order = determine_size_order();
   
   if(waitingTime < 0)
   	wait = 0;

   	new_customer->waiting_time = 0;
   	wait = (serviceTime + waitingTime)-(time - lastArrivingTime);
   	
		
   printf("%d ", serviceTime);
   printf("%d ", time);
	printf("%d ", lastArrivingTime);
	printf("%da ", serviceTime+ waitingTime);
	printf("%da ", serviceTime);
	printf("%da ", wait);
	printf("%da \n", time - lastArrivingTime);
		  	
 	if (customers_in_lineA <= customers_in_lineB)  /* check for shorter line and add customer */
	{
			customers_in_lineA++;			/* incrament line A's counter for ID assignment */
		/*	enqueue(queueA, customers_in_lineA); */
	   	new_customer-> ID = customers_in_lineA;
			new_customer->line = 'A'; 		/* specify which line the customer will be in */
	   		
			if (new_customer->size_order == 1)  /* if order is small */
			{
				lineA_money = lineA_money + small_price;
				total_money = total_money + small_price;
				new_customer->service_time = 1;	/* customer will wait 1 minute at service */
			} 
			
			if (new_customer->size_order == 2)   /* if order is medium */ 
			{
				lineA_money = lineA_money + medium_price;				
				total_money = total_money + medium_price;
				new_customer->service_time = 2; /* customer will wait 2 minutes at service */
			}
			
			if (new_customer->size_order == 3)  /* if order is large */
			{
				lineA_money = lineA_money + large_price;
				total_money = total_money + large_price;
				new_customer->service_time = 4; /* customer will wait 4 minutes at service */
			}
			
	   } 
	   else
	   {
	   		customers_in_lineB++;           /* incrament line B's counter for ID assignment */
	   		/*enqueue(queueB, customers_in_lineB);*/
	   		new_customer-> ID = customers_in_lineB;
	   		new_customer->line = 'B';  /* specify which line the customer will be in */	
	   		
			if (new_customer->size_order == 1)  /* if order is small */
			{
				lineB_money = lineB_money + small_price;
				total_money = total_money + small_price;
				new_customer->service_time = 2;	/* customer will wait 2 minutes at service */
			} 
			
			if (new_customer->size_order == 2)  /* if order is medium */
			{
				lineB_money = lineB_money + medium_price;
				total_money = total_money + medium_price;
				new_customer->service_time = 3; /* customer will wait 3 minutes at service */
			}
			
			if (new_customer->size_order == 3) /* if order is large */
			{
				lineB_money = lineB_money + small_price;
				total_money = total_money + medium_price;
				new_customer->service_time = 5; /* customer will wait 5 mintues at service */
			} 
	   }
	   
	new_customer->total_service_time = new_customer->waiting_time + new_customer->service_time;
	
	serviceTime = new_customer->service_time; 
	waitingTime = wait;
   lastArrivingTime = new_customer->arrival_time;
   
}


/*This is a part from the main function*/
	SetRandomSeed();
	do{			
			if (ShouldAddCustomer(arrivalRate) == 1)  /* if the return value is 1, a customer is created */
			{
				CreateCustomer(timeStep);
			   number_customers++;	
			}						
		timeStep++;    /* incrament a time step */ 
		
	  }while (timeStep <= time_max);
Last edited on
waitingTime is not defined
lastArrivingTime is not defined
serviceTime is not defined

are these globals?
Yes they are globals
ok. what do you think it should print? is the value of waitingTime supposed to be? You said the others are ok so I assume you know the value of serviceTime & that is ok, and you try to print serviceTime+waitingTime... if that answer is not correct, waitingTime has to be incorrect...

being a global, does anything else modify it? Was it initialized? Again, what should it be, and what is it, and if those don't match, who modified it incorrectly... this is what you need to find.

which may or may not be a classic example of why globals cause problems (here, something maybe modified it unexpectedly which affected a totally different function..)

also, is this meant to be pure C? (It looks to be).
Last edited on
Topic archived. No new replies allowed.