0

I have created the code for managing the counters of a post office / bank, but I am not sure about my solution. Could anyone please give me some advice? Thank you for your availability.

Here is the text with the minimum requirements:

Develop a program that manages access to the counters of a post office in compliance of the following minimum requirements. 1. Number of branches/windows: 3.enter code here 2. Number of services: 2 (A and B). 3. At the entrance of the room there is a device that allows the user to select the desired service and, after selection, provides the user with a ticket with the information: 1) service requested (A or B) 2) progressive number assigned for the selected service. 4. When one of the branches completes the operation with the user served, the employee at the counter presses a button to call the next user in the queue for one of the two services. 5. The program warns the user that he must approach one of the counters by viewing the call information (counter number, service and user progressive number) on a display place in the waiting room. For example, the following indication that appears on the display invites user No. 14 for service A to go to counter n ° 1. SP SRV N 1 to 14

And the code

 #include <stdio.h>
 #include <string.h>
 #include <time.h>
 #include <stdlib.h>

 #define MAXLOCAL       100
 #define lenght         15

 typedef enum {true, false} bool;

 int main()
 {
    int contA = 0; // Clients A service counter
    int contB = 0; // Clients B service counter
    int tot_client = 0; // Total number of clients
    int val; // Value
    char ch; // Choiche
    int nRandomNumber; // Random number between 1...3
    const int nMax = 4;
    const int nMin = 1; 
    char signal[lenght]; // Signal

    bool Exit = true;

    do
    {
        srand(time(NULL));
        nRandomNumber = 0; // Initially initialized at 0
        nRandomNumber = rand() % (nMax-nMin) + nMin; // Random number generator

        printf("Welcome! Select the desired service:(A / B) \n");
        fflush(stdin);
        scanf(" %c", &ch);

        if((ch == 'A') || (ch == 'a'))
        {
            contA++;
            tot_client++;
            printf("Service required : %c    Number of service %c : %d \n ", ch, ch, contA );
            printf("\n");
            printf(" SP: %d  SRV: %c  N: %d \n ", nRandomNumber, ch, contA );
        }
        else
        {
            if((ch == 'B') || (ch == 'b'))
            {
                contB++;
                tot_client++;
                printf("Service required : %c    Number of service %c : %d \n ", ch, ch, contB );
                printf("\n");
                printf(" SP: %d  SRV: %c  N: %d \n ", nRandomNumber, ch, contB );
            }
            else
            {
                printf("Wrong service selected. Try again \n ");
            }
        }

        printf("\n");

        printf("0 ---> EXIT / to remain press any other key \n ");
        fflush(stdin);
        scanf(" %c", &val);

        if(val == '0')
        {
            printf("Processing... \n ");
            scanf(" %s", signal);

            if(strncmp(signal, "Exit", 4) == 0)
            {

                if(Exit == true)
                {
                    printf("Thank you and see you soon \n ");
                    tot_client--;
                }
            }
        }
    }while(tot_client <= MAXLOCAL);

    printf("The service is temporarily unavailable \n ");

    return 0;
} 
  • `srand(time(NULL));` only needs to be called once, you can pull it out of the loop. – yano Mar 09 '20 at 14:00
  • 1
    What is the problem, more exactly? What part isn't working? – Lundin Mar 09 '20 at 14:01
  • 1
    Only post if you have a specific problem. This community is not for code review. – jjsantoso Mar 09 '20 at 14:01
  • `fflush(stdin);` is undefined behavior: https://stackoverflow.com/questions/18170410/what-is-the-use-of-fflushstdin-in-c-programming – yano Mar 09 '20 at 14:02
  • recommend using `else if` .. it's a cleaner look and allows for easier future expansion – yano Mar 09 '20 at 14:09
  • I have this doubt. when a customer withdraws the ticket, the program prints the number of the counter where to be served. So it never happens that the customer waits in the waiting room. – Tyler Lambert Mar 09 '20 at 14:14

0 Answers0