提问人:Iver 提问时间:11/30/2022 最后编辑:Iver 更新时间:11/30/2022 访问量:48
使用用户输入更改打印语句
Changing the printed statement using user input
问:
我目前正在为我们的编程主题开发一个 C 语言的商店管理程序,我想找出更改程序中打印语句的代码。我想在以下使用用户输入来更改打印的语句:
经销商名单、客户名单、员工名单。
这是我的代码:
#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;
}
使用(用户输入)添加或删除经销商、客户、员工,我想使用用户输入(经销商列表、客户列表、员工列表)更改这些部分中的打印报表。
另外,您如何看待我的代码?
谢谢。
编辑(澄清):
例如,我想发生:
我选择了“添加经销商”选项,并输入了“Cafe Tokyo”,当我再次查看时,Cafe Tokyo应该会显示在“经销商列表”中。
选择“删除经销商”选项也是如此,例如,我想让马尼拉咖啡馆消失,我将进入马尼拉咖啡馆,一旦我查看经销商列表,马尼拉咖啡馆就不应该在那里。
答: 暂无答案
评论