C++ Online Compiler
Example: Menu with Single Item Selection in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Menu with Single Item Selection #include <iostream> using namespace std; int main() { int choice; int totalBill = 0; // Step 1: Display the menu cout << "Welcome to Our Hotel!" << endl; cout << "---------------------" << endl; cout << "Our Menu:" << endl; cout << "1. Coffee - Rs. 50" << endl; cout << "2. Tea - Rs. 40" << endl; cout << "3. Sandwich - Rs. 120" << endl; cout << "4. Burger - Rs. 180" << endl; cout << "5. Pizza - Rs. 350" << endl; cout << "---------------------" << endl; // Step 2: Get user's choice cout << "Enter your choice: "; cin >> choice; // Step 3: Process the choice using a switch statement switch (choice) { case 1: cout << "You selected: Coffee. Rs. 50" << endl; totalBill += 50; break; case 2: cout << "You selected: Tea. Rs. 40" << endl; totalBill += 40; break; case 3: cout << "You selected: Sandwich. Rs. 120" << endl; totalBill += 120; break; case 4: cout << "You selected: Burger. Rs. 180" << endl; totalBill += 180; break; case 5: cout << "You selected: Pizza. Rs. 350" << endl; totalBill += 350; break; default: cout << "Invalid choice. Please select a valid item." << endl; break; } // Step 4: Display the current total (after one selection) cout << "---------------------" << endl; cout << "Your Current Bill: Rs. " << totalBill << endl; cout << "Thank you!" << endl; return 0; }
Output
Clear
ADVERTISEMENTS