用C语言实现简单菜单

本文展示了一个使用C语言创建简单菜单的实例,用于查询不同城市的航班时刻表,包括Atlanta、Boston、Los Angeles和New York的航班信息。程序中包含了主菜单的打印、用户输入处理及各城市航班时刻的显示。

通过本实例简单了解C语言实现菜单的基本原理。

实例中没有什么过多深入的东西,仅仅是简单实现基本的菜单。

 

本实例是查询航班时刻表:

 

/************************************************************************/

/*C语言实现 */ /*运行环境:VC++6.0                                                */

/************************************************************************/

 

#include "stdio.h"

#include "conio.h"

#include "stdlib.h"

int PrnMainMenu(void); 

void ProcessLoop(void);  

void Atlanta(void);   

void Boston(void);      

void LosAngeles(void); 

void Miami(void); 

void NewYork(void);    

main()        /*主函数*/

{

     ProcessLoop();

     return 0;

}

void ProcessLoop(void)

 {

     int iChoice;

    iChoice = PrnMainMenu();

     while (iChoice != 6)

     {

         switch(iChoice)

         {

        case 1:

            Atlanta();

             break;

         case 2:

            Boston();

            break;

        case 3:

             LosAngeles();

            break;

        case 4:

            Miami();

            break;

        default:

            NewYork();

            break;

        }

         iChoice = PrnMainMenu();

    }

    return;

}

 

int PrnMainMenu(void)

{

     int iChoice;

    system("cls");  /*_clearscreen(0); */

     printf("/n/t%s","wynfield metro airport");

     printf("/n/n/t                   main menu");

     printf("/n/n/n/t                   Select one:");

     printf("/n/n/t                   1.Atlanta");

     printf("/n/n/t                   2.Boston");

     printf("/n/n/t                   3.Los Angeles");

     printf("/n/n/t                   4.Miami");

     printf("/n/n/t                   5.New York");

    printf("/n/n/t                   6.Quit");

     printf("/n/n/n/n/n/n/t           Enter choice(1-6)===>");

     scanf("%d",&iChoice);     fflush(stdin);

     while (iChoice < 1 || iChoice > 6)

     {

        printf("/nERROR...re-enter choice(1-6)===>");

        scanf("%d",&iChoice);

         fflush(stdin);

     }

     return iChoice;

 }

 

void Atlanta(void)

{

     char cWait;

    system("cls");

    printf("/n/t%s","wynfield metro airport");

     printf("/n/n/t            Atlanta Flight Schedule");

     printf("/n/n/n/t   ------------------------------");

     printf("/n/n/t    Flight#         Departure");

     printf("/n/n/t    101             7:15 p.m");

     printf("/n/n/t    214             9:20 p.m");

     printf("/n/n/n/t      Press Enter to continue...");

     cWait = getch();

     return;

 }

 

void Boston(void)

{

     char cWait;

    system("cls");

     printf("/n/t%s","wynfield metro airport");

     printf("/n/n/t           Boston Flight Schedule");

     printf("/n/n/n/t   ------------------------------");

     printf("/n/n/t    Flight#         Departure");

     printf("/n/n/t    117             5:55 p.m");

     printf("/n/n/t    201             6:30 p.m");

     printf("/n/n/n/t      Press Enter to continue...");

     cWait = getch();

     return;

 }

 

void LosAngeles(void)

 {

     char cWait;

    system("cls");

     printf("/n/t%s","wynfield metro airport");

     printf("/n/n/t           LosAngeles Flight Schedule");

     printf("/n/n/n/t   --------------------------------");

     printf("/n/n/t    Flight#         Departure");

     printf("/n/n/t    122             3:10 p.m");

     printf("/n/n/t    205             4:30 p.m");

     printf("/n/n/n/t      Press Enter to continue...");

     cWait = getch();

     return;

 }

 

void Miami(void)

 {

     char cWait;

    system("cls");

     printf("/n/t%s","wynfield metro airport");

     printf("/n/n/t           Miami Flight Schedule");

     printf("/n/n/n/t   ------------------------------");

     printf("/n/n/t    Flight#         Departure");

     printf("/n/n/t    102             1:25 p.m");

     printf("/n/n/t    204             4:00 p.m");

     printf("/n/n/n/t      Press Enter to continue...");

     cWait = getch();

     return;

 }

 

void NewYork(void)

{

     char cWait;

    system("cls");

     printf("/n/t%s","wynfield metro airport");

     printf("/n/n/t           NewYork Flight Schedule");

     printf("/n/n/n/t   ------------------------------");

     printf("/n/n/t    Flight#         Departure");

     printf("/n/n/t    104             2:00 p.m");

     printf("/n/n/t    119             5:16 p.m");

     printf("/n/n/t    200             7:20 p.m");

     printf("/n/n/n/t      Press Enter to continue...");

     cWait = getch();

     return;

 }

 

 

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值