#include <iostream>
#include <cstdio>
char *menu[]={"wwerwerwe",
"----------",
"1,asdasda",
"2,2345",
"3,345",
"0,qiut",
"---------",
"Please choice:"};
int f1() //f1~f3为对应1、2、3选项的功能
{ printf("12344345/n"); }
int f2()
{ printf("2343454/n"); }
int f3()
{ printf("345345435/n"); }
int (*fun[])()={f1,f2,f3};//函数指针数组 typedef int (*Fptr)( ); Fptr fun[ ]={f1,f2,f3};
void pause() //pause、cls为使得程序通用性更强
{ system("pause"); }
void cls() { system("cls"); }
void displayMenu()
{ int i;
int menuNumber=sizeof(menu)/sizeof(char*);
cls();
for(i=0;i<menuNumber-1;i++)
printf("/t%s/n",menu[i]);
printf("/t%s",menu[i]);
}
int choice()
{ int t;
scanf("%d",&t);
while(t<0||t>sizeof(menu)/sizeof(char*)-5)
{
cls();
displayMenu();
scanf("%d",&t);
}
return t;
}
int main()
{ int i;
while(1)
{
displayMenu();
i=choice();
if(i==0) break;
else { (*fun[i-1])( ); pause(); }
}
return 0;
}
Console通用菜单程序设计
最新推荐文章于 2024-09-16 07:34:53 发布