In: Computer Science
Summary
The cost of renting a room at a hotel is, say $100.00 per night. For special occasions, such as a wedding or conference, the hotel offers a special discount as follows.
If the number of rooms booked is:
Also if rooms are booked for at least three days, then there is an additional 5% discount.
Instructions
Write a program that prompts the user to enter:
The program outputs:
Your program must use appropriate named constants to store special values such as various discounts.
Since your program handles currency, make sure to use a data type that can store decimals with a precision to 2 decimals.
SOLUTION:-
#include<iostream>
using namespace std;
int main()
{
double rent, s_tax, discount = 0;
int n, days;
double roomRent, totalRent,sales_tax;
// Entry of user
cout<<"Enter the rent of one room:$ ";
cin>>rent;
cout<<"Enter the number of rooms to be booked: ";
cin>>n;
cout<<"Enter the number of days for which rooms need to be booked: ";
cin>>days;
cout<<"Enter the sales tax (in %): ";
cin>>s_tax;
// if rooms is greater than or equal to 30,give the discount of 30%
if(n>=30)
discount = 0.3;
// if rooms is greater than or equal to 20,give the discount of 20%
else if(n>=20)
discount = 0.2;
// if rooms is greater than or equal to 10,give the discount of 10%
else if(n>=10)
discount = 0.1;
// if days is greater than or equal to 3 add additional 5%
if(days>=3)
discount += 0.05;
// calculation of total rent
totalRent = rent*n*days*(1-discount);
roomRent = totalRent/n;
// print the output
cout<<"The cost of renting one room is "<<roomRent<<endl;
cout<<"The discount given is "<<100*discount<< "%.\n";
cout<<"The number of rooms booked is "<<n<<endl;
cout<<"The number of days rooms booked is "<<days<<endl;
cout<<"Total cost of the rooms = "<<totalRent<<endl;
sales_tax = (s_tax*totalRent)/100;
cout<<"Sales tax = "<<sales_tax<<endl;
// generate total bill
cout<<"Total bill = "<<totalRent + sales_tax<<endl;
return 0;
}