C語言編程例子-使用while為用戶提供菜單顯示


演示版本

VS2012

  • 使用while為用戶提供菜單顯示

實例說明:

在使用程序時,根據程序的功能會有許多選項,為了使用戶可以方便地觀察到菜單的選項,

要將其菜單進行輸出。在本實例中,利用while將菜單進行循環輸出,這樣可以使用戶更為

清楚地知道選擇每一項所對應的操作。

#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_s("%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://默認處理
            break;
        }
    }

    return 0;
}

 

阿飛

2021年8月7日


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM