Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define TRUE 1
- #define FALSE 0
- int main(void)
- {
- int selection;
- srand(time(NULL));
- printf("~~ FAST FOOD RESTARAUNT SIMULATION ~~\n\nPress 1 to initialize scenario 1. \nPress 2 to initialize scenario 2. \nAny other key will exit the program.\n\nSelection: ");
- scanf("%d",&selection);
- switch(selection)
- {
- case 1:
- scenarioOne();
- break;
- case 2:
- scenarioTwo();
- break;
- default:
- break;
- }
- return 0;
- }
- int scenarioOne(void)
- {
- printf("SCENARIO ONE CHOSEN.\n\n");
- /// USER DEFINES CUSTOMERS PER MINUTE
- double r;
- printf("Define the arrival rate of customers per minute: ");
- scanf("%lf",&r);
- /// CUSTOMERS PER SECOND
- double customerArrive; // the chance a customer will arrive at any given second
- customerArrive=(r*1.0)/60;
- printf("Theoretically, there will be %f customers arriving per second.\n Press 'Enter' to continue.\n",customerArrive);
- getchar();
- getchar();
- /// EACH ITERATION IS A 10-MINUTE INTERVAL
- // THIS IS WRONG. TWO FOR-LOOPS CANNOT MAKE TIME A CONTINUOUS FUNCTION...
- int i;
- for (i=0; i<18; i++)
- interval(customerArrive);
- }
- int interval(double customerArrive)
- {
- // Counter to determine which interval is currently running.
- static int intNum;
- intNum++;
- printf("---------------------------INTERVAL %d------------------------\n\n",intNum);
- int totalCustomer=0; // total # of customers
- int completedOrder=0; // total # of completed orders
- int totalOrderWait=0; // total wait time for ORDERS
- int totalDelayWait=0; // total wait time for DELAYS
- int avgWait=0; // AVERAGE wait time
- int delay1=0; // delay time
- int delay2=0; // delay time
- int queue=0; // customer queue count
- int cash1empty=1; // whether or not a customer can get served by cash 1
- int cash2empty=1; // whether or not a customer can get served by cash 2
- int cash1salad,cash1burger,cash2salad,cash2burger; // different types of orders
- /// EACH ITERATION IS ONE SECOND
- int t;
- for (t=0;t<600;t++)
- {
- /// Generate random value between 0 and 1. Used as a decimal to compare to chance of customer arrival
- double x;
- x= (double) rand() / (double) RAND_MAX;
- if (customerArrive>=x)
- {
- // A customer arrived during this second!
- totalCustomer++;
- queue++;
- }
- if (queue > 0)
- {
- // In the case that both cashiers are empty, the program must decide where the customer goes with a coin toss
- if ((cash1empty==TRUE)&&(cash2empty==TRUE))
- {
- switch((rand()%2))
- {
- case 0:
- cash2empty=FALSE;
- break;
- case 1:
- cash1empty=FALSE;
- break;
- }
- }
- if (delay1>0)
- {
- delay1--;
- totalDelayWait++;
- cash1empty=FALSE;
- }
- else
- cash1empty=TRUE;
- if (cash1empty==TRUE)
- {
- cash1empty=FALSE;
- queue--;
- printf("Cash 1 is being used.\n");
- switch((rand()%2))
- {
- case 0:
- cash1salad=(rand()%(66-55)+55);
- printf("At t=%d, salad order took %d seconds at Cash 1.\n\n",t,cash1salad);
- delay1=cash1salad;
- totalOrderWait+=cash1salad;
- completedOrder++;
- break;
- case 1:
- cash1burger=(rand()%(131-111)+111);
- printf("At t=%d, burger order took %d seconds at Cash 1.\n\n",t,cash1burger);
- delay1=cash1burger;
- totalOrderWait+=cash1burger;
- completedOrder++;
- break;
- }
- }
- else if (cash2empty==TRUE)
- {
- cash2empty=FALSE;
- queue--;
- printf("Cash 2 is being used.\n");
- switch(rand()%2)
- {
- case 0:
- cash2salad=(rand()%(76-65)+65);
- printf("At t=%d, salad order took %d seconds at Cash 2.\n\n",t,cash2salad);
- delay2=cash2salad;
- totalOrderWait+=cash2salad;
- completedOrder++;
- break;
- case 1:
- cash2burger=(rand()%(141-121)+121);
- printf("At t=%d, burger order took %d seconds at Cash 2. \n\n",t,cash2burger);
- delay2=cash2burger;
- totalOrderWait+=cash2burger;
- completedOrder++;
- break;
- }
- }
- }
- }
- // customer arrival rate per minute, by probability
- double R;
- R=(totalCustomer*1.0)/600;
- printf("Customers arriving per minute in interval %d: %f\n",intNum,R);
- if (completedOrder>0)
- {
- avgWait=((totalOrderWait+totalDelayWait)/(completedOrder));
- printf("Amount of customers that showed up: %d\n",totalCustomer);
- printf("Amount of customers that had their order completed: %d\n",completedOrder);
- printf("In total, %d seconds were spent by people lining up.\n",totalDelayWait);
- printf("In total, %d seconds were spent by people taking orders.\n",totalOrderWait);
- if (avgWait>=0)
- {
- printf("Average wait time per customer: %d\n\n",avgWait);
- }
- }
- else
- {
- printf("No customers arrived in this interval.\n\n");
- }
- printf("-----------------------END OF INTERVAL %d---------------------\n\n",intNum);
- }
- int scenarioTwo(void)
- {
- printf("SCENARIO TWO CHOSEN.\n\n");
- // scenario two is not yet programmed...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement