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

C Language: The goal is to create a drug dispensing program that has 4 drugs and

ID: 3722742 • Letter: C

Question

C Language: The goal is to create a drug dispensing program that has 4 drugs and allows a user to check quantities, refill, and dispense. A user must first login with the following credentials before the menu becomes available Username: Admin01 Password: L3tM3in The 4 drugs and their initial quantities are Tylenol 40 Advil 40 Ibuprofen 30 Codeine 10 If either username or password are incorrect, console will clear, and the program will stay at the log in screen. If credentials are correct and user presses enter, console will clear, and a menu will be displayed. If option 1 is selected, the console is cleared, and the current quantity of each drug is displayed. A user presses b to go back to menu. If option 2 is selected, the console is cleared, and a prompt asks a user to select a drug and then enter a quantity to refill with. The program updates quantity and goes back to the main menu Need to select option 1 from main menu to see if results are updated From the menu, if option 3 is selected, the program will prompt the user to select a drug and how much to dispense. When the user presses enter, the program goes back to the main menu. Option 1 must be selected to verify result of dispense.

Explanation / Answer

here is your program : ------------->>>>>>>>

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


void menu(){
system("cls");
printf("---------------------------------------------------------------------------------------------- ");
printf("                                 WELCOME TO DRUG DISPENSARY ");
printf("---------------------------------------------------------------------------------------------- ");
printf(" 1 : Display DRUG ");
printf(" 2 : Update DRUG ");
printf(" 3 : Dispense DRUG ");
printf(" 4 : QUIT ");
}

void display(char *arg[4],int quan[4]){
int i;
system("cls");
printf(" sl No. Name        Quantity ");
for(i = 0;i<4;i++){
  printf(" %d   %s %d",i+1,arg[i],quan[i]);
}
}

int logIn(){
char user_id[10];
char pass[10];
system("cls");
printf("------------------- LOG IN ------------------");
printf(" USER NAME : ");
scanf("%s",&user_id);
printf(" PASSWORD : ");
scanf("%s",&pass);
if(strcmp(user_id,"Admin01") == 0 && strcmp(pass,"L3tM3in") == 0){
  return 1;
}

return 0;
}


int main(){
char *arg[4] = {"Tylenol ","Advil    ","Ibuprofen","Codeine "};
int quan[4] = {40,40,30,10};
char ch = '0';

while(logIn() == 0);
while(ch != '4'){
  menu();
  printf(" Enter your option : ");
  scanf("%c",&ch);
  switch(ch){
   case '1':
    {
     display(arg,quan);break;
    }
   case '2':
    {
     display(arg,quan);
     int n;
     printf(" Choose from above drug : ");
     scanf("%d",&n);
     if(n > 0 && n <= 4){
      int am;
      printf(" Enter Quantity To Update : ");
      scanf("%d",&am);
      quan[n-1] = quan[n-1] + am;
     }else{
      printf(" Not Correct option");
     }
     break;
    }
   case '3':
    {
     display(arg,quan);
     int n;
     printf(" Choose from above drug : ");
     scanf("%d",&n);
     if(n > 0 && n <= 4){
      int am;
      printf(" Enter Quantity To Dispense : ");
      scanf("%d",&am);
      if(am <= quan[n-1] && am > 0){
       quan[n-1] = quan[n-1] - am;
      }else if(am > quan[n-1]){
       printf(" Not Enough DRUG");
      }
     }else{
      printf(" Not Correct option");
     }
     break;
    }
  }
  getch();
}
}