C++ Program To Make Hotel Menu Card
Creating a digital menu for a hotel or restaurant can streamline the ordering process and improve customer experience. In this article, you will learn how to build a C++ program that functions as a simple interactive hotel menu card.
Problem Statement
Traditional paper menus can be cumbersome to update, prone to wear and tear, and may not offer a dynamic experience. The problem is to develop a basic console-based C++ application that displays a hotel menu, allows customers to select items, and calculates their total bill, offering a simple digital alternative.
Example
The program will present a menu and allow a user to select items, ultimately displaying a total. Here's a glimpse of what a user interaction might look like:
Welcome to Our Hotel!
---------------------
Our Menu:
1. Coffee - Rs. 50
2. Tea - Rs. 40
3. Sandwich - Rs. 120
4. Burger - Rs. 180
5. Pizza - Rs. 350
6. Exit & Pay
---------------------
Enter your choice: 1
You selected: Coffee. Rs. 50
Do you want to add more items? (y/n): y
Enter your choice: 3
You selected: Sandwich. Rs. 120
Do you want to add more items? (y/n): n
---------------------
Your Total Bill: Rs. 170
Thank you for your order!
Background & Knowledge Prerequisites
To understand and implement the C++ menu card program, you should be familiar with:
- C++ Basics: Fundamental syntax, data types (int, char, float), and variables.
- Input/Output (I/O): Using
coutfor output andcinfor input. - Conditional Statements:
if-elseandswitchstatements for decision-making. - Loops:
whileordo-whileloops for repeating actions.
Relevant Imports and Setup:
The primary header file needed will be for console input and output.
Use Cases or Case Studies
A console-based menu card program, even a simple one, can be useful in several scenarios:
- Small Cafeterias/Stalls: For quick order taking where a full-fledged POS system is overkill.
- Learning & Development: As a practical exercise for students learning C++ programming fundamentals.
- Internal Testing: To simulate order placement for testing backend systems or new menu item pricing.
- Offline Order Entry: In environments with limited internet access, a robust console application can still function.
- Training Simulations: To train new staff members on menu items and basic order processing before moving to complex systems.
Solution Approaches
We will explore three approaches, progressively adding more features to the menu card program.
Approach 1: Simple Console Menu Display
This approach focuses on just displaying the menu items and their prices without any interaction.
- One-line summary: Display a static list of menu items and prices to the console.
// Simple Hotel Menu Display
#include <iostream>
using namespace std;
int main() {
// Step 1: Display a welcome message
cout << "Welcome to Our Hotel!" << endl;
cout << "---------------------" << endl;
// Step 2: Display the menu items with prices
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;
return 0;
}
- Sample Output:
Welcome to Our Hotel!
---------------------
Our Menu:
1. Coffee - Rs. 50
2. Tea - Rs. 40
3. Sandwich - Rs. 120
4. Burger - Rs. 180
5. Pizza - Rs. 350
---------------------
- Stepwise Explanation:
- The program starts by including the
iostreamlibrary for input/output operations. - It then prints a welcome message and a separator line.
- Finally, it prints each menu item along with its corresponding price, each on a new line, to display the complete menu.
Approach 2: Menu with Item Selection and Total Bill
This approach adds interactivity, allowing the user to select one item and see its price, then calculates a total if multiple items (fixed number) were selected. For simplicity, we'll demonstrate a single selection and then a simple hardcoded total for context.
- One-line summary: Allow a user to select a single menu item and display its cost.
// 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;
}
- Sample Output (User chooses Coffee):
Welcome to Our Hotel!
---------------------
Our Menu:
1. Coffee - Rs. 50
2. Tea - Rs. 40
3. Sandwich - Rs. 120
4. Burger - Rs. 180
5. Pizza - Rs. 350
---------------------
Enter your choice: 1
You selected: Coffee. Rs. 50
---------------------
Your Current Bill: Rs. 50
Thank you!
- Stepwise Explanation:
- The program initializes an integer
choiceto store user input andtotalBillto track costs. - It displays the menu similar to Approach 1.
- The user is prompted to enter their choice, which is read into the
choicevariable. - A
switchstatement evaluates thechoice:- For each valid case (1-5), it prints the selected item and adds its price to
totalBill.
- For each valid case (1-5), it prints the selected item and adds its price to
break statement exits the switch after a match.default case handles invalid inputs.- Finally, it prints the current
totalBill.
Approach 3: Menu with Loop for Multiple Orders and Final Bill
This advanced approach allows customers to order multiple items, continuously adding to their bill until they choose to finalize the order.
- One-line summary: Implement a looping menu that allows repeated item selection and calculates a running total bill.
// 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;
}
- Sample Output:
Welcome to Our Hotel!
---------------------
Our Menu:
1. Coffee - Rs. 50
2. Tea - Rs. 40
3. Sandwich - Rs. 120
4. Burger - Rs. 180
5. Pizza - Rs. 350
6. Exit & Pay
---------------------
Enter your choice: 1
You selected: Coffee. Rs. 50
Do you want to add more items? (y/n): y
---------------------
Our Menu:
1. Coffee - Rs. 50
2. Tea - Rs. 40
3. Sandwich - Rs. 120
4. Burger - Rs. 180
5. Pizza - Rs. 350
6. Exit & Pay
---------------------
Enter your choice: 3
You selected: Sandwich. Rs. 120
Do you want to add more items? (y/n): y
---------------------
Our Menu:
1. Coffee - Rs. 50
2. Tea - Rs. 40
3. Sandwich - Rs. 120
4. Burger - Rs. 180
5. Pizza - Rs. 350
6. Exit & Pay
---------------------
Enter your choice: 6
---------------------
Your Total Bill: Rs. 170
Thank you for your order!
- Stepwise Explanation:
- The program initializes
choice,totalBill, and a charactercontinueOrderto 'y' to control the main loop. - A
whileloop runs as long ascontinueOrderis 'y' or 'Y', allowing multiple orders. - Inside the loop, the menu is displayed, and the user is prompted for their choice.
- The
switchstatement processes the choice, adding the item's price tototalBill. - A new option (6) is added to
Exit & Pay. If selected,continueOrderis set to 'n', which will terminate thewhileloop. - After processing a choice (and if not exiting via option 6), the program asks the user if they want to add more items. Their 'y' or 'n' input updates
continueOrder. - Once the
whileloop terminates (either by choosing 'n' or '6'), the finaltotalBillis displayed, and a thank you message is shown.
Conclusion
Developing a C++ program for a hotel menu card demonstrates fundamental programming concepts like input/output, conditional logic, and looping. From a simple display to an interactive ordering system, these examples illustrate how to build practical applications step by step. Such a program, while console-based, forms the bedrock for more sophisticated point-of-sale systems.
Summary
- Basic Menu Display: Using
coutto present a static list of items and prices. - Interactive Selection: Incorporating
cinandswitchstatements to allow users to select menu items. - Total Bill Calculation: Accumulating costs in a
totalBillvariable based on user selections. - Multiple Orders: Employing a
whileloop to enable customers to order several items before finalizing their bill. - Input Validation: Using a
defaultcase in theswitchstatement to handle invalid menu choices.