Hi there,
I have been working on a program that has the following features and have come pretty close to what I believe is a final product.
1) Choose a random integer from 1 to 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 from 1 to 4);
Begin servicing the customer;
Schedule arrival time of next customer (random integer 1 to 4 added to the current time).
3) For each minute of the day:
If the next customer arrives,
Say so, enqueue the customer, and schedule the arrival time of the next
customer;
If service was completed for the last customer;
Say so, dequeue next customer to be serviced and determine customer’s
service completion time (random integer from 1 to 4 added to the
current time).
Now the issue I am having is that when I run my program the starting customers when I scroll up are starting around 620 - 630 instead of 1 to 4 like I would expect. Below is my code, could any one point me in the right direction?
thank you!
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
|
#include <iostream>
#include <string>
#include<list>
#include<ctime>
#include<cstdlib>
#include<iomanip>
using namespace std;
const int FULL_DAY = 720;
unsigned int determineServiceTime();
unsigned int determineArrivalTime();
int main()
{
srand(static_cast< int>(time(0)));
unsigned int minute_counter = 1, arrival_time = 0, service_time = 0;
list <int> arrivalTime;
list <int> serviceTime;
while(minute_counter < FULL_DAY)
{
arrival_time += determineArrivalTime();
arrivalTime.push_back(arrival_time);
cout << "Customer will arrive at mintute " << arrivalTime.front() << endl;
service_time += determineServiceTime();
serviceTime.push_back(service_time);
cout << "Customer will be served at mintute " << serviceTime.front() << endl;
if(minute_counter == arrivalTime.front())
{
cout << "Costumer has arrived at minute: " << arrivalTime.front() << endl;
cout << "Customer has been enqueued." << endl;
arrivalTime.pop_front();
}
if(minute_counter == serviceTime.front())
{
cout << "Customer has been served at minute " << serviceTime.front() << endl;
cout << "Customer has been dequeued." << endl;
serviceTime.pop_front();
}
minute_counter++;
}
}
unsigned int determineServiceTime()
{
unsigned int chance = 1 + rand() % 4;
return chance;
}
unsigned int determineArrivalTime()
{
unsigned int chance = 1 + rand() % 4;
return chance;
}
|