C++ Online Compiler
Example: Interactive Hotel Menu Card with Total Bill in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Interactive Hotel Menu Card with Total Bill #include <iostream> using namespace std; int main() { int choice; int totalBill = 0; char continueOrder = 'y'; // Flag to control the ordering loop cout << "Welcome to Our Hotel!" << endl; // Step 1: Main ordering loop while (continueOrder == 'y' || continueOrder == 'Y') { 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 << "6. Exit & Pay" << endl; cout << "---------------------" << endl; // Step 2: Get user's choice cout << "Enter your choice: "; cin >> choice; // Step 3: Process the choice and update bill 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; case 6: // Option to exit and pay continueOrder = 'n'; // Set flag to exit loop break; default: cout << "Invalid choice. Please select a valid item." << endl; break; } // Step 4: Ask if the user wants to add more items, unless they chose to exit if (continueOrder == 'y' || continueOrder == 'Y') { // Only ask if not exiting via choice 6 cout << "Do you want to add more items? (y/n): "; cin >> continueOrder; } } // Step 5: Display the final bill cout << "---------------------" << endl; cout << "Your Total Bill: Rs. " << totalBill << endl; cout << "Thank you for your order!" << endl; return 0; }
Output
Clear
ADVERTISEMENTS