#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
int main(void)
{
int selection;
printf("~~ FAST FOOD RESTARAUNT SIMULATION ~~\n\nPress 1 to initialize scenario 1. \nPress 2 to initialize scenario 2. \nPress any other key to 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 'r' customers that'll show up 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
int i;
for (i=0; i<18; i++)
interval(customerArrive);
}
int interval(double customerArrive)
{
int totalCustomer=0; // total # of customers
int totalWait=0; // total wait time
int avgWait=0; // AVERAGE wait time
int queue=0; // length of queue
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.
double x;
x= (double) rand() / (double) RAND_MAX;
if (customerArrive>=x)
{
// A customer arrived during this second!
totalCustomer++;
// if both cashiers are empty, then it is 50/50 to decide where to go
if ((cash1empty==TRUE)&&(cash2empty==TRUE))
{
switch((rand()%2))
{
case 0:
cash1empty=FALSE;
break;
case 1:
cash2empty=FALSE;
break;
}
}
if (cash1empty==TRUE)
{
cash1empty=FALSE;
switch((rand()%2))
{
case 0:
cash1salad=(rand()%(66-55)+55);
totalWait+=cash1salad;
break;
case 1:
cash1burger=(rand()%(131-111)+111);
totalWait+=cash1burger;
break;
}
}
else if (cash2empty=TRUE)
{
cash2empty=FALSE;
switch(rand()%2)
{
case 0:
cash2salad=(rand()%(76-65)+65);
totalWait+=cash2salad;
break;
case 1:
cash2burger=(rand()%(141-121)+121);
totalWait+=cash2burger;
break;
}
}
else
{
queue++;
/// I DON'T KNOW WHAT I'M DOING.
}
}
else
{
/// DO NOTHING
// A customer did not arrive during this second.
}
}
/// extra code: just to check
// Counter to determine which interval is currently running.
static int intNum;
intNum++;
/// extra code: just to check
// 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);
avgWait=((totalWait*1.0)/(totalCustomer));
printf("Average wait time per customer: %d\n",avgWait);
/// extra code : just to check
printf("queue=%d\n\n",queue);
}