Write a program that calculates the occupancy rate for a hotel. The program should start by asking the
user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration,
the loop should ask the user for the number of rooms on the floor and how many of them are occupied.
After all the iterations, the program should display how many rooms the hotel has, how many of them
are occupied, how many are unoccupied, and the percentage of rooms that are occupied. The
percentage may be calculated by dividing the number of rooms occupied by the number of rooms.
Input Validation: Do not accept a value less than 1 for the number of floors. Do not accept a number
less than 10 for the number of rooms on a floor.
#include <iostream>
using namespace std;
int main(){
int number_of_floors, number_of_rooms_in_floor, occupied_rooms_in_floor;
int total_occupied_rooms = 0, total_unonccupied_rooms = 0, total_number_of_rooms = 0;
do{
cout<<"Input the number of floors in hotel: ";
cin>>number_of_floors;
}while(number_of_floors < 1);
for(int i = 0; i < number_of_floors; i++){
do{
cout<<"Input the number of rooms in floor "<<i + 1<<endl;
cin>>number_of_rooms_in_floor;
}while(number_of_rooms_in_floor < 10);
total_number_of_rooms += number_of_rooms_in_floor;
do{
cout<<"Input the number of occupied rooms in floor "<<i + 1<<endl;
cin>>occupied_rooms_in_floor;
}while(occupied_rooms_in_floor < 0);
total_occupied_rooms += occupied_rooms_in_floor;
total_unonccupied_rooms += number_of_rooms_in_floor - occupied_rooms_in_floor;
}
float occupancy_rate = (float) total_occupied_rooms / total_number_of_rooms * 100;
cout<<"Total Number of rooms: "<<total_number_of_rooms<<endl;
cout<<"Total occupied rooms: "<<total_occupied_rooms<<endl;
cout<<"Total unoccupied rooms: "<<total_unonccupied_rooms<<endl;
cout<<"Occupancy rate: "<<occupancy_rate<<"%"<<endl;
return 0;
}
Comments
Leave a comment