Iver
Iver

Reputation: 11

Changing the printed statement using user input

I am currently working on a store management program in C for our programming subject and I want to find out the code to change the printed statements in my program. I want to change the printed statements using user input in the following:

List of Dealers, List of Customers, List of Employees.

Here is my code:

#include <stdio.h>

int main() 
{
int sx;
int sc;
char ca[30];
char cnt;

do{
   printf("STORE MANAGEMENT SYSTEM\n");
   printf("=========================\n");
   printf("1. Dealer Menu\n");
   printf("2. Customer Menu\n");
   printf("3. Employee Menu\n");
   printf("4. Exit\n");
   printf("Enter your choice: ");
   scanf("%d", &sx);
   
    switch(sx)
       {
           case 1:
                printf("DEALER MENU SELECTED\n");
                printf("=========================\n");
                printf("1. List of dealers\n");
                printf("2. Add a dealer\n");
                printf("3. Remove a dealer\n");
                printf("Enter your choice: ");
                scanf("%d", &sc);
                
                if(sc == 1)
                {
                    printf("LIST OF DEALERS SELECTED\n");
                    printf("=========================\n");
                    printf("1. Cafe Manila\n");
                    printf("2. Cafe Hong Kong\n");
                    printf("Do you want to continue? Y/N? \n");
                    scanf("%s", &cnt);
                }
                
                else if(sc == 2)
                {
                    printf("ADD A DEALER SELECTED\n");
                    printf("=========================\n");
                    printf("Enter a dealer to be added: ");
                    scanf("%s", &ca);
                    printf("%s successfully added\n", ca);
                    printf("Do you want to continue? Y/N?\n");
                    scanf("%s", &cnt);
                }
                
                else if(sc == 3)
                {
                    printf("REMOVE A DEALER SELECTED\n");
                    printf("=========================\n");
                    printf("Enter a dealer to be removed: ");
                    scanf("%s", &ca);
                    printf("%s successfully removed\n", ca);
                    printf("Do you want to continue? Y/N?\n");
                    scanf("%s", &cnt);
                }
                
                else
                {
                    printf("INVALID INPUT\n");
                    printf("Do you want to continue? Y/N?\n");
                    scanf("%s", &cnt);
                }
                break;
                
            case 2:
                printf("CUSTOMER MENU SELECTED\n");
                printf("=========================\n");
                printf("1. List of customers\n");
                printf("2. Add a customer\n");
                printf("3. Remove a customer\n");
                printf("Enter your choice: ");
                scanf("%d", &sc);
                
                if(sc == 1)
                {
                    printf("LIST OF CUSTOMERS SELECTED\n");
                    printf("=========================\n");
                    printf("1. John\n");
                    printf("2. Juan\n");
                    printf("Do you want to continue? Y/N? \n");
                    scanf("%s", &cnt);
                }
                
                else if(sc == 2)
                {
                    printf("ADD A CUSTOMER SELECTED\n");
                    printf("=========================\n");
                    printf("Enter a customer to be added: ");
                    scanf("%s", &ca);
                    printf("%s successfully added\n", ca);
                    printf("Do you want to continue? Y/N?\n");
                    scanf("%s", &cnt);
                }
                
                else if(sc == 3)
                {
                    printf("REMOVE A CUSTOMER SELECTED\n");
                    printf("=========================\n");
                    printf("Enter a customer to be removed: ");
                    scanf("%s", &ca);
                    printf("%s successfully removed\n", ca);
                    printf("Do you want to continue? Y/N?\n");
                    scanf("%s", &cnt);
                }
                
                else
                {
                    printf("INVALID INPUT\n");
                    printf("Do you want to continue? Y/N?\n");
                    scanf("%s", &cnt);
                }
                break;
                
            case 3:
                printf("EMPLOYEE MENU SELECTED\n");
                printf("=========================\n");
                printf("1. List of employees\n");
                printf("2. Add an employee\n");
                printf("3. Remove an employee\n");
                printf("Enter your choice: ");
                scanf("%d", &sc);
                
                if(sc == 1)
                {
                    printf("LIST OF EMPLOYEES SELECTED\n");
                    printf("=========================\n");
                    printf("1. Juan\n");
                    printf("2. John\n");
                    printf("Do you want to continue? Y/N? \n");
                    scanf("%s", &cnt);
                }
                
                else if(sc == 2)
                {
                    printf("ADD AN EMPLOYEE SELECTED\n");
                    printf("=========================\n");
                    printf("Enter an employee to be added: ");
                    scanf("%s", &ca);
                    printf("%s successfully added\n", ca);
                    printf("Do you want to continue? Y/N?\n");
                    scanf("%s", &cnt);
                }
                
                else if(sc == 3)
                {
                    printf("REMOVE AN EMPLOYEE SELECTED\n");
                    printf("=========================\n");
                    printf("Enter an employee to be removed: ");
                    scanf("%s", &ca);
                    printf("%s successfully removed\n", ca);
                    printf("Do you want to continue? Y/N?\n");
                    scanf("%s", &cnt);
                }
                
                else
                {
                    printf("INVALID INPUT\n");
                    printf("Do you want to continue? Y/N?\n");
                    scanf("%s", &cnt);
                }
                break;
                
            case 4:
                printf("Exit Program.....");
                break;
                
            default:
                printf("Invalid Input\n");
                printf("Do you want to continue? Y/N?\n");
                scanf("%s", &cnt);
                break;
       }
       
       if(cnt == 'n' || cnt == 'N')
       {
           printf("Exit Program.....");
       }
}
while(cnt == 'y' || cnt == 'Y');

    return 0;
}

Using the (user input) add or remove a dealer, customer, employee, I want to change the printed statements in these section using user input (List of Dealers, List of Customers, List of Employees).

Also, what do you think about my code?

Thanks.

Edit (Clarification):

I want to happen is for example:

I selected the "Add a Dealer" choice, and entered "Cafe Tokyo", the Cafe Tokyo should show up in the "List of Dealers" once I view it again.

Same thing goes for selecting the "Remove a Dealer" choice, for example I want to make Cafe Manila disappear, I'll enter Cafe Manila and once I view the list of dealers, Cafe Manila should not be there.

Upvotes: 1

Views: 52

Answers (0)

Related Questions