Description
The purpose of this challenge is to use looping (WHILE) and conditional constructs (IF-ELSE, IF-ELSE-IF, nested IF statements). This challenge simulates a hotel reservation system.
Requirements
- Ask the user to enter their first name. Don’t forget to first declare a variable for the first name.
- Ask the user to enter their last name. Don’t forget to first declare a variable for the last name.
- Ask the user to enter their age. Don’t forget to first declare a variable for the age.
- If the user is younger than 21 yrs old, display a message indicating that they cannot make a hotel reservation and ask the user again to enter a valid age. HINT: This is Input Validation that uses a WHILE loop. The program won’t continue past this point if the user keeps entering an age younger than 21.
- Ask the user what kind of bed is preferred (king size, queen size, twin). You must use an if-else-if construct to display a friendly message about the selected bed type. (Hint: Use a char variable)
- Ask the user how many nights the reservation will include
- Ask the user what room type is preferred (beach view, city view, balcony, garden view. In this hotel, all room reservations typically cost $100/night. However, Beach View rooms cost $25 more. You can use any IF construct here (IF, IF-ELSE, IF-ELSE-IF, nested IFs).
- Additionally, rooms with king size beds cost $10 more. This cost is added to the room cost regardless of room type.
- Display a message indicating the cost of the reservation. A 5% city tax is also added to the cost.
DO NOT USE
You may not use any looping mechanisms or user-defined functions.
Sample Interaction / Output
It's a lovely day at the Challenge Hotel! Please enter your first name to begin your reservation: Will And your last name: Power Thank you, Will Power, how old are you? 15 Sorry, you must be at least 21 years old to make a reservation. Please enter a valid age: 19 Sorry, you must be at least 21 years old to make a reservation. Please enter a valid age: 20 Sorry, you must be at least 21 years old to make a reservation. Please enter a valid age: 37 Great! We have rooms with different types of beds You can choose from (K - King, Q - Queen, T - Twin) What's your preference? K Awesome! Our king size beds are amazing! How many nights will you be staying? 2 Last question, what kind of room would you like, we have: B - Beach View C - City View Y - Balcony G - Garden View What's your preference? B Will, your room is reserved for 2 nights. Your Beach View room with a king size bed will be ready. Please pay $283.50.
In the sample interaction above, the final bill is calculated as $100 + $25 + $10 per room (surcharges for Beach View and King Size bed), for 2 nights, plus tax. Make sure you test your code with various combinations of rooms and beds.
Hints
- It’s good practice to initialize variables to default values that make sense
- Include the <iomanip> header file. This will allow you to use various options to format your output such as setprecision
- Include the code below before any other cout lines. The setprecision(x) will display your decimal output with x decimal places.
cout << fixed << setprecision(2);
LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT
CATALOG ID: CPP-FLOW0003c
Print Requirements