Hi all. I am currently at a standstill with the project I am working on. The context is as follows:

A Doctors surgery needs a computer program to provide self-service to patients. Patients use this console to check in on arrival to the surgery. They can also use the console to enquire about their position in the waiting list, or to find out how many doctors are currently available at the surgery. The program is also used by doctors to check out (discharge) patients when they have finished examining them. Doctors use the program as well to check in and out of their rooms.The program must maintain a waiting list (queue) of all checked in patients, and as soon as one of the doctors is free, the program must call on the next patient in the queue by displaying a message.

I have managed to implement the queue, which I will post below so you can see what functions I've used for it.

What I'm struggling with is how I would tie this in to the ten rooms with Doctors. I want to create functions that do the following:

-A command that displays the number of doctors currently available at the surgery, and a list of all examination rooms that are currently staffed

-A command used by a doctor when they arrive at their room and they are ready to see patients. When this command is executed, the program must automatically call on the next patient in the queue, and instruct them to proceed to a room

-A command is used by doctors to check out (or formally discharge) a patient from the surgery.

I have a function (remove_nth in my code) that can remove specific elements of the queue defined by the user. I was thinking I could use this to discharge patients, but I'm just a bit stumped as to how to tie everything together. Any help would be greatly appreciated. Thank you.

Code:

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <stdbool.h> 
#define MAX 6


/*FUNCTION PROTOTYPES START*/


void insert(int data);
void dequeue();
void position(int n);
void print();
void remove_nth(int n);
void help(void);
void status();
void queue_display();
void loading();
int first();
int last();
bool is_empty();
bool is_full();


/*FUNCTION PROTOTYPES FINISH*/


/*GLOBAL VARIABLE DECLARATIONS START*/


int queue[MAX]; //Queue for patients waiting
int room_no[10] = {1,2,3,4,5,6,7,8,9,10}; //Array for Doctors rooms
int room;
int front = -1; //Front of queue
int rear = -1;  //Back of queue
int num = -1;
int pos = 1; //Position of a number in an array


/*GLOBAL VARIABLE DECLARATIONS FINISH*/


int main(int argc, char * * argv) {
   //Declare our variables


   /*Patient Commands*/
   char i; //Patient check in
   char p; //Patient queue position
   char q; //Patient quit
   char d; //Available doctors
   char h; //Help - display commands
   /*Doctors Commands*/
   char o; //Paitient check out
   char r; //Doctor ready
   char a; //Doctor away
   char w; //Waiting list
   char x; //Exit
   /*Other*/
   char choice;
   char s; //Room status (for testing purposes)
   int id; //Argument for functions


   printf("Hello and welcome to Mo's Surgery\n");
   printf("Press RETURN to continue...\n");
   getchar();
   system("clear");
   printf("Loading...\n\n");
   //For loop to add delay to give loading effect
   int c = 1, k = 1;
   for (c = 1; c <= 32767; c++)
      for (k = 1; k <= 32767; k++) {}


   do {
      printf("\nMo's Surgery\n");
      printf("-------------\n");
      printf("Enter a command\n");
      printf("hint - to view available commands enter 'h'\n");
      printf(">>>");
      scanf(" %c", & choice);


      switch (choice) {
      case 'h':
         loading();
         system("clear");
         help();
         break;


      case 'i':
         loading();
         system("clear");
         scanf(" %d", & id);
         insert(id);
         break;


      case 'p':
         loading();
         system("clear");
         scanf("%d", & id);
         position(id);
         break;


      case 'q':
         loading();
         system("clear");
         scanf(" %d", & id);
         cancel(id);
         break;


      case 'd':
         loading();
         system("clear");


         break;


      case 'o':
         loading();
         system("clear");
         scanf("%d", & id);
         remove_nth(id);
         break;


      case 'r':
         loading();
         system("clear");
         dequeue();
         break;


      case 'a':
         loading();
         system("clear");


         break;


      case 's':
         loading();
         system("clear");
         status();
         break;


      case 'w':
         loading();
         system("clear");
         print();
         break;


      case 'u':
         queue_display();
         break;


      case 'x':
         loading();
         system("clear");
         exit(1);
         break;


      default:
         printf("Error, command not recognised. Please enter a valid command.\n");
      }
   } while (choice != 'x');


   return 0;


}


/*HELP FUNCTION */


void help() {
   printf("Patient commands\n");
   printf("----------------------\n");
   printf("i - Check in on arrival\n");
   printf("p - Check position in queue\n");
   printf("q - Cancel appointment\n");
   printf("d - View # of available Doctors\n\n");
   printf("Administrator commands only\n");
   printf("------------------------------\n");
   printf("o - Check patient out\n");
   printf("r - Call patient\n");
   printf("a - Doctor away\n");
   printf("w - View waiting list\n\n");
   printf("Other\n");
   printf("----------\n");
   printf("x - Exit\n\n");
}


/*QUEUE 'IS EMPTY' FUNCTION*/


bool is_empty() {
   if (front == -1 && rear == -1)
      return true;
   else
      return false;
}


/*QUEUE 'IS FULL' FUNCTION*/


bool is_full() {
   if ((rear == MAX - 1 && front == 0) || (front == rear + 1))
      return true;


   else {
      return false;
   }
}


/*ENQUEUE FUNCTION (Inserts element at rear end)*/


void insert(int data) {
  if (is_full())
    printf("\nSorry, the waiting queue is full. Please try again later.\n");
  else {
    if (rear == MAX - 1 && front != 0)
      rear = -1;
    queue[++rear] = data;
    printf("\nWelcome Patient No. %d\nAll Doctors a busy right now.\nPlease relax in the waiting area.\n\n", data);
    if (front == -1)
      front = 0;
  }


  for (int i = front; i <= rear; i++) {
    if (queue[i % MAX] == data) {
      printf("Position in queue is %d \n\n", (i % MAX + 1) - front);
    } else {
      for (int i = 0; i < 6; i++) {
        if (data = queue[i])
          printf("You are already checked in!\n");
        printf("Position in queue is %d \n\n", (rear + MAX - front) % MAX + 1);
      }
    }


  }


}


/*DEQUEUE FUNCTION (Removes element in queue from front end)*/


void dequeue() {
   if (is_empty())
      printf("\nNothing in queue!!!\n");
   else {
      printf("\n%d has been removed from the queue.\n", queue[front++]);
      if (front == MAX)
         front = 0;
      if (front - 1 == rear)
         front = rear = -1;
   }
}


/*FIRST FUNCTION (Returns element at front of queue)*/


int first() {
   if (front == -1) {
      puts("Error: cannot return front from empty queue");
      return -1;
   } else {
      printf("%d\n\n", queue[front]);
   }
}


/*LAST FUNCTION (Returns element at back of queue)*/


int last() {
   if (rear == -1) {
      puts("Error: cannot return rear from empty queue");
      return -1;
   } else {
      printf("%d\n\n", queue[rear]);
   }
}


/*PRINT FUNCTION (Prints out queue)*/


void print() {
   if (front == -1)
      printf("\nNothing to display\n");
   else {
      int i = front;
      printf("\nThe following patients are waiting: \n");
      if (front <= rear) {
         while (i <= rear)
            printf("%d\t", queue[i++]);
      } else {
         while (i <= MAX - 1)
            printf("%d\t", queue[i++]);
         i = 0;
         while (i <= rear)
            printf("%d\t", queue[i++]);
         printf("\n");
      }
   }
}


/*POSITION FUNCTION (Tells user their position in the queue)*/


void position(int n) {
   for (int i = front; i <= rear; i++) {


      if (i >= front) pos = i - front;
      else pos = MAX - (n - front);


      {
         printf("You are in the queue!\n\n");
         printf("Position in queue is %d \n\n", (rear + MAX - front) % MAX + 1);
         return;
      }
   }
}


/*REMOVE NTH FUNCTION (Removes nth element from queue)*/


void remove_nth(int n) {
   int i;
   if ((front == -1) && (rear == -1)) {
      printf("Queue is empty! Nothing to remove.\n");
      return;
   }
   for (i = 0; i <= rear; i++) {
      if (n == queue[i]) {
         for (; i < rear; i++) {
            queue[i] = queue[i + 1];
         }
         queue[i] = 0;
         rear--;
         if (rear == -1)
            front = -1;
         printf("Succesfully deleted\n\n");
         return;
      }
   }
   printf("\n%d not found in queue to delete\n\n", n);
}


/*STATUS FUNCTION (Checks if rooms are available or not)*/


void status() {


   for (int i = 0; i < 10; i++)
      printf("Room %d\n", room_no[i]);
   printf("\n");
}


/*CANCEL FUNCTION (Allows patient to cancel appt. (similair to remove_nth))*/


void cancel(int n) {
   int i;
   if ((front == -1) && (rear == -1)) {
      printf("Queue is empty! Nothing to cancel.\n");
      return;
   }
   for (i = 0; i <= rear; i++) {
      if (n == queue[i]) {
         for (; i < rear; i++) {
            queue[i] = queue[i + 1];
         }
         queue[i] = 0;
         rear--;
         if (rear == -1)
            front = -1;
         printf("Appointment successfully canceled\n\n");
         return;
      }
   }
   printf("\n%d not found in queue to delete\n\n", n);


}


void queue_display() {
   for (int i = 0; i < 6; i++)
      printf("%d\t", queue[i]);
      printf("\n");
      printf("front = %d\n", queue[front]);
      printf("rear = %d\n", queue[rear]);
      print("\n");
}


void loading() {
  int c, k;
   printf("Loading...\n\n");
   //For loop to add delay to give loading effect
   c = 1,  k = 1;
   for (c = 1; c <= 32767; c++)
      for (k = 1; k <= 32767; k++) {}
}


bool is_value_in(int val, int *arr, int size){
    int i;
    for (i=0; i < size; i++) {
        if (array[i] == val)
            return true;
    }
    return false;
}