20. switch语句

创建日期:2024-07-14
更新日期:2025-02-01

switch.cpp

#include <iostream>

using namespace std;
void showmenu();
void report();
void comfort();
int main()
{
    showmenu();
    int choice;
    cin >> choice;
    while (choice != 5)
    {
        switch (choice)
        {
        case 1:
            cout << "\a\n";
            break;
        case 2:
            report();
            break;
        case 3:
            cout << "The boss was in all day.\n";
            break;
        case 4:
            comfort();
            break;
        default:
            cout << "That's not a choice.\n";
        }
        showmenu();
        cin >> choice;
    }
    cout << "Bye!\n";
}

void showmenu()
{
    cout << "Please enter 1, 2, 3, 4, or 5:\n"
         << "1) alarm            2) report\n"
         << "3) alibi            4) comfort\n"
         << "5) quit\n";
}

void report()
{
    cout << "It's been an excellent week for business.\n"
            "Sales are up 120%. Expenses are down 35%.\n";
}

void comfort()
{
    cout << "YOur employees think you are the finese CEO\n"
            "in the industry. The board of directors think\n"
            "you are the finese CEO in the industry.\n";
}