I need help with my program.
It will not recognize whether or not a customer has arrived.
I have a feeling that the timer isn't working either.
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
|
#include "Queue.h"
#include <cstdlib>
#include <ctime>
void main()
// Description: main entry point of program
// Parameters: none
// Returns: nothing
{
Queue<int> checkout;
srand(time(0)); // random number gen
int timer = 0;
int start = rand() % 4 + 1;
int service = 0;
int next = 0;
int maxQ = 0;
int maxW = 0;
int temp = 0;
while(timer < 50)
{
cout << endl << "Time : " << timer+1 << " : Actions for this time" << endl;
if (timer == start)
{
service = rand() % 4 + 1;
next = rand() % 4 + 1 + timer;
checkout.enQueue(timer);
}
else if (timer == next)
{
cout << "Customer just arrived." << endl;
checkout.enQueue(timer);
next = rand() % 4 + 1 + timer;
}
if (service == 0)
{
cout << "Customer finished." << endl;
service = rand() % 4 + 1;
checkout.deQueue(temp);
if (temp > maxW)
maxW = temp;
}
if (checkout.getQueue() > maxQ)
maxQ = checkout.getQueue();
next--;
service--;
temp++;
timer++;
} // end while
}
|
Here is my problem:
1) Choose a random integer between 1 and 4 to determine the minute at which the first customer arrives.
2) At the first customer's arrival time;
*Determine customer's service time (random integer 1 to 4)
*Begin Servicing the customer;
*Schedule arrival time of the next customer (random integer 1 to 4 added to the current time)
3) For each minute of the day:
*If the customer arrives;
- say so, enqueue the customer;
- schedule the arrival time of the next customer;
*If service was completed for the last customer;
- say so,
- dequeue next customer to be serviced
- determine customers completion time (random integer from 1 to 4 o the current time)
Correct me if i'm wrong, but my program SHOULD be doing that. yet it only shows the first customer arriving. |