2. Sy residences owns 5 condominium units which is located to different cities in the Philippines. The units are used to accommodate travelers from all over the world. Each unit has a base price of 3,000 per night. Units are good for 4 persons only, however the guest can pay an extra charge of 500 per person in excess. Children below 4 years old are free. Guests will be given 10% discount for more than a week of stay. 15% for more than 15 days and 20% for a month. Write a program that will ask the user to enter the number of days that the guest will stay, total number of guests that will check in, number of children below 4 years old and display the total amount that the user will pay. Sample Output Welcome to Sy Residences! Please enter the number of days that you will stay: 5 Number of Guests: 5 Number of children below 4 years old: 0 Total Amount that the guest will pay: 17500
Below is my C++ code. Can I make it shorter?
#include <iostream>
using namespace std;
int main()
{
int days, guests, children_below_4;
float total;
cout<< "Welcome to Sy Residences! \n";
cout<< "Please enter the number of days that you will stay: ";
cin>>days;
cout<< "Number of Guests: ";
cin>>guests;
cout<< "Number of children below 4 years old: ";
cin>>children_below_4;
total = (3000*days);
if (guests <=4) {
total = total;
cout<< "Total amount that the guest will pay: " <<total;
}
else {
total = total + (days)*(500)*(guests - children_below_4 - 4);
cout<< "Total amount that the guest will pay: " <<total;
if (days <= 7) {
total = total;
cout<< "Total amount that the guest will pay: " <<total;
}
else if (days >= 30){
total = (total)*(0.80);
cout<< "Total amount that the guest will pay: " <<total;
}
else {
switch(days)
{
case 8:
total= (total)*(0.90);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 9:
total= (total)*(0.90);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 10:
total= (total)*(0.90);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 11:
total= (total)*(0.90);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 12:
total= (total)*(0.90);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 13:
total= (total)*(0.90);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 14:
total= (total)*(0.90);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 15:
total= (total)*(0.90);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 16:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 17:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 18:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 19:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 20:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 21:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 22:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 23:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 24:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 25:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 26:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 27:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 28:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
case 29:
total= (total)*(0.85);
cout<< "Total amount that the guest will pay: " <<total;
break;
default:
cout<<"Your input is invalid.";
}
}
return 0;
}
Step by step
Solved in 3 steps with 2 images