1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #define TRUE 1
  5. #define FALSE 0
  6.  
  7. int main(void)
  8. {
  9.     int selection;
  10.  
  11.     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: ");
  12.     scanf("%d",&selection);
  13.  
  14.     switch(selection)
  15.     {
  16.         case 1:
  17.             scenarioOne();
  18.             break;
  19.         case 2:
  20.             scenarioTwo();
  21.             break;
  22.         default:
  23.             break;
  24.     }
  25. return 0;
  26. }
  27.  
  28. int scenarioOne(void)
  29. {
  30.     printf("SCENARIO ONE CHOSEN.\n\n");
  31.  
  32. /// USER DEFINES CUSTOMERS PER MINUTE
  33.     double r;
  34.     printf("Define 'r' customers  that'll show up per minute: ");
  35.     scanf("%lf",&r);
  36.  
  37. /// CUSTOMERS PER SECOND
  38.     double customerArrive; // the chance a customer will arrive at any given second
  39.     customerArrive=(r*1.0)/60;
  40.     printf("Theoretically, there will be %f customers arriving per second.\n Press 'Enter' to continue.\n",customerArrive);
  41.  
  42.         getchar();
  43.         getchar();
  44.  
  45. /// EACH ITERATION IS A 10-MINUTE INTERVAL
  46.     int i;
  47.     for (i=0; i<18; i++)
  48.         interval(customerArrive);
  49. }
  50.  
  51. int interval(double customerArrive)
  52. {
  53.         int totalCustomer=0; // total # of customers
  54.         int totalWait=0; // total wait time
  55.         int avgWait=0; // AVERAGE wait time
  56.  
  57.         int queue=0; // length of queue
  58.  
  59.         int cash1empty=1; // whether or not a customer can get served by cash 1
  60.         int cash2empty=1; // whether or not a customer can get served by cash 2
  61.  
  62.         int cash1salad,cash1burger,cash2salad,cash2burger; // different types of orders
  63.  
  64.         /// EACH ITERATION IS ONE SECOND
  65.             int t;
  66.             for (t=0;t<600;t++)
  67.             {
  68.                 /// Generate random value between 0 and 1.
  69.                     double x;
  70.                     x= (double) rand() / (double) RAND_MAX;
  71.  
  72.                 if (customerArrive>=x)
  73.                 {
  74.  
  75.                     // A customer arrived during this second!
  76.                     totalCustomer++;
  77.  
  78.                     // if both cashiers are empty, then it is 50/50 to decide where to go
  79.                     if ((cash1empty==TRUE)&&(cash2empty==TRUE))
  80.                     {
  81.                         switch((rand()%2))
  82.                         {
  83.                             case 0:
  84.                                 cash1empty=FALSE;
  85.                                 break;
  86.                             case 1:
  87.                                 cash2empty=FALSE;
  88.                                 break;
  89.  
  90.                         }
  91.                     }
  92.  
  93.                     if (cash1empty==TRUE)
  94.                     {
  95.                         cash1empty=FALSE;
  96.  
  97.                         switch((rand()%2))
  98.                         {
  99.                             case 0:
  100.                                 cash1salad=(rand()%(66-55)+55);
  101.                                 totalWait+=cash1salad;
  102.                                 break;
  103.                             case 1:
  104.                                 cash1burger=(rand()%(131-111)+111);
  105.                                 totalWait+=cash1burger;
  106.                                 break;
  107.                         }
  108.                     }
  109.                     else if (cash2empty=TRUE)
  110.                     {
  111.                         cash2empty=FALSE;
  112.  
  113.                         switch(rand()%2)
  114.                         {
  115.                             case 0:
  116.                                 cash2salad=(rand()%(76-65)+65);
  117.                                 totalWait+=cash2salad;
  118.                                 break;
  119.                             case 1:
  120.                                 cash2burger=(rand()%(141-121)+121);
  121.                                 totalWait+=cash2burger;
  122.                                 break;
  123.                         }
  124.                     }
  125.                     else
  126.                     {
  127.                         queue++;
  128.                         /// I DON'T KNOW WHAT I'M DOING.
  129.                     }
  130.  
  131.                 }
  132.                 else
  133.                 {
  134.                    /// DO NOTHING
  135.                    // A customer did not arrive during this second.
  136.                 }
  137.             }
  138.  
  139.  
  140.             /// extra code: just to check
  141.             // Counter to determine which interval is currently running.
  142.             static int intNum;
  143.             intNum++;
  144.  
  145.  
  146.             /// extra code: just to check
  147.             // customer arrival rate per minute, by probability
  148.             double R;
  149.             R=(totalCustomer*1.0)/600;
  150.             printf("Customers arriving per minute in interval %d: %f\n",intNum,R);
  151.  
  152.  
  153.             avgWait=((totalWait*1.0)/(totalCustomer));
  154.             printf("Average wait time per customer: %d\n",avgWait);
  155.  
  156.             /// extra code : just to check
  157.             printf("queue=%d\n\n",queue);
  158.  
  159. }