我是一名新的计算机科学专业的学生,我目前正在从事超级商店管理系统的大学项目。
为此,我想要一个菜单系统。我尝试过使用开关盒
它可以工作,但是,例如,当我按1
程序进入我定义的另一个函数时。
但主菜单功能仍然显示在顶部 我想要一个菜单,我将按下一个数字,程序将继续执行某个功能,清除我之前使用的命令。
任何帮助将不胜感激。谢谢。
(我尝试使用switch case。我是新手,对文件处理和那种东西一无所知)
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
//User defined function declaration
int main_menu();
int products();
double payment();
int customer();
//User defined sub menus
//under products
int home_products();
int electronics();
int add_products();
int remove_products();
int products_quantity();
//Under payment
double billing();
//under customer menu()
int customer_inf();
int edit_customer();
int main ()
{
int input;
printf(" Hello ADMIN\n SHIRONAMHIN Super Shop\n================================================================================");
printf(" -Products\n -Payment/Billing\n -Customer information\n");
printf("\n");
printf(" Press One for Products \n Press two for Billing \n Press Three for Customer information \n Press 0 to terminate program");
scanf("\n%d", &input);
if(input==0)
{
return 0; //Program will be terminated if 0 is pressed
}
switch(input)
{
case 1:
if(input==1)
{
products();
}
break;
case 2:
if(input==2)
{
payment();
}
break;
case 3:
if(input==3)
{
customer();
}
break;
default:
printf("Enter a valid number");
break;
}
}
int products()
{
int input;
printf("\n -Home products\n -Electronics\n\n Press any key rather than 1 and 2 two return to main menu");
scanf("%d", &input);
switch (input)
{
case 1:
if(input == 1)
home_products();
break;
case 2:
if(input == 2)
electronics();
break;
default:
main();
break;
}
}
int home_products()
{
int input;
printf("Code yet to be written\n\n return to main menu by pressing 1 on the keyboard");
scanf("%d", &input);
if(input == 1)
{
return main();
}
}
int electronics()
{
printf("Code yet to be written");
}
double payment()
{
return main();
}
int customer()
{
printf("Code yet to be written");
return main();
}