Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you help make my code take and call more names in line. Right now it only ca

ID: 3821783 • Letter: C

Question

Can you help make my code take and call more names in line. Right now it only calls 2 names. PLEASE add comments

(( output should look like this ))
0.Call a custmer
1.Add a customer
2.Quit
Enter your choice: 1
Enter the customer name to be placed in call: tom
0.Call a custmer
1.Add a customer
2.Quit
Enter your choice: 1
Enter the customer name to be placed in call: peter
0.Call a custmer
1.Add a customer
2.Quit
Enter your choice: 1
Enter the customer name to be placed in call: bob
0.Call a custmer
1.Add a customer
2.Quit
Enter your choice: 0
Name of the customer in line: tom
0.Call a custmer
1.Add a customer
2.Quit
Enter your choice: 0
Name of the customer in line: peter
0.Call a custmer
1.Add a customer
2.Quit
Enter your choice: 0
Name of the customer in line: bob
0.Call a custmer
1.Add a customer
2.Quit
Enter your choice: 2

#include

Explanation / Answer

PROGRAM CODE:

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

struct node
{
   char name[50];
   struct node*next;
};
typedef struct node Node;
Node *list;

int main(void) {
   int choice;
   do
   {
       printf(" 0. call 1. Add 2. Exit");
       printf(" Enter your choice: ");
       scanf("%d", &choice);
       if(choice == 0)
       {
           if(list == NULL)
           {
               printf("List is empty ");
           }
           else
           {
               Node *temp;
               printf(" Name of the customer in line: %s ", list->name);
               if(list->next != NULL)
               {
                   temp = list->next;
                   free(list);
                   list = temp;
               }
               else
               list = NULL;
           }
       }
       else if(choice == 1)
       {
           char str[50];
           Node *temp;
           printf(" Enter the customer name to be placed in the call: ");
           scanf("%s", str);
           temp = (Node*)malloc(sizeof(Node));
           strcpy(temp->name, str);
           temp->next = NULL;
           if(list == NULL)
           {
               list = temp;
           }
           else
           {
               //Made changes only here to keep on adding more names
               Node *temp1 = list;
               while(temp1->next != NULL)
                   temp1 = temp1->next;
               temp1->next = temp;
           }
       }
   }while(choice != 2);
   return 0;
}

OUTPUT:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote