用C语言编写,使用while为用户提供菜单显示

2025-11-14 06:46:03

1、打开visual C++ 6.0-文件-新建-文件-C++ Source File

用C语言编写,使用while为用户提供菜单显示

用C语言编写,使用while为用户提供菜单显示

2、定义变量:

#include<stdio.h>

int main()

{

    int iSelect=1;                                          /*定义变量,表示菜单的选项*/

用C语言编写,使用while为用户提供菜单显示

3、循环显示菜单:

    while(iSelect!=0)                                       /*检验条件,循环显示菜单*/

    {   /*显示菜单内容*/

        printf("---------Menu---------\n");

        printf("----Sell----------1\n");

        printf("----Buy-----------2\n");

        printf("----ShowProduct---3\n");

        printf("----Out-----------0\n");

用C语言编写,使用while为用户提供菜单显示

4、输入菜单的选项:

        scanf("%d",&iSelect);                                /*输入菜单的选项*/

用C语言编写,使用while为用户提供菜单显示

5、判断选项:

        switch(iSelect)                                     /*使用switch语句,检验条件进行相应的处理*/

        {

            case 1:                                     /*选择第一项菜单的情况*/

                printf("you are buying something into store\n");

                break;

用C语言编写,使用while为用户提供菜单显示

6、            case 2:                                     /*选择第二项菜单的情况*/

                printf("you are selling to consumer\n");

                break;

用C语言编写,使用while为用户提供菜单显示

7、            case 3:                                     /*选择第三项菜单的情况*/

                printf("checking the store\n");

                break;

用C语言编写,使用while为用户提供菜单显示

8、            case 0:                                     /*选择退出项菜单的情况*/

                printf("the Program is out\n");

                break;

            default:                                    /*默认处理*/

                printf("You put a wrong selection\n");

                break;

        }

    }

    return 0;

用C语言编写,使用while为用户提供菜单显示

9、完整的源代码:

#include<stdio.h>

int main()

{

    int iSelect=1;                                          /*定义变量,表示菜单的选项*/

    while(iSelect!=0)                                       /*检验条件,循环显示菜单*/

    {   /*显示菜单内容*/

        printf("---------Menu---------\n");

        printf("----Sell----------1\n");

        printf("----Buy-----------2\n");

        printf("----ShowProduct---3\n");

        printf("----Out-----------0\n");

        scanf("%d",&iSelect);                                /*输入菜单的选项*/

        switch(iSelect)                                     /*使用switch语句,检验条件进行相应的处理*/

        {

            case 1:                                     /*选择第一项菜单的情况*/

                printf("you are buying something into store\n");

                break;

            case 2:                                     /*选择第二项菜单的情况*/

                printf("you are selling to consumer\n");

                break;

            case 3:                                     /*选择第三项菜单的情况*/

                printf("checking the store\n");

                break;

            case 0:                                     /*选择退出项菜单的情况*/

                printf("the Program is out\n");

                break;

            default:                                    /*默认处理*/

                printf("You put a wrong selection\n");

                break;

        }

    }

    return 0;

}

用C语言编写,使用while为用户提供菜单显示

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢