Here is an example of a menu in C++:

#include <iostream>
using namespace std;

int main() {
    int choice;
    do {
        cout << 'Menu:' << endl;
        cout << '1. Option 1' << endl;
        cout << '2. Option 2' << endl;
        cout << '3. Option 3' << endl;
        cout << '4. Exit' << endl;
        cout << 'Enter your choice: ';
        cin >> choice;
        switch (choice) {
            case 1:
                // code for option 1
                break;
            case 2:
                // code for option 2
                break;
            case 3:
                // code for option 3
                break;
            case 4:
                cout << 'Goodbye!' << endl;
                break;
            default:
                cout << 'Invalid choice. Please try again.' << endl;
                break;
        }
    } while (choice != 4);
    return 0;
}

This menu displays four options and allows the user to enter their choice. If the user enters an invalid choice, the program displays an error message and prompts them to try again. The program continues to display the menu until the user chooses to exit.

C++ Menu Code Example: Simple & Efficient

原文地址: https://www.cveoy.top/t/topic/lyX8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录