Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program in C++that calculates the occupancy rate for each floor of a hot

ID: 3621765 • Letter: W

Question

write a program in C++that calculates the occupancy rate for each floor of a hotel . the program should start by asking for the number of floors that the hotel has. a loop should then iterate once for each floor during each iteration the loop prompts the user for the number of rooms on the floor and how many of them are occupied . after all the iterations the program should then display the number of rooms the hotel has , the number occupied, the number vacant and the occupancy rate. your program should not accept a value less than 1 for the number of floors and a value less than 10 for the number of rooms on the floor.

Explanation / Answer

#include<iostream>
using namespace std;

int main()
{
int i, floors, rooms[100], filled[100];
double total_rooms=0, total_filled=0;

do{
cout << " Enter the total number of floors in the hotel: ";
cin >> floors;
if(floors<1)
cout<<"Invalid Input. The number of floors cannot be lesser than 1";
}while(floors<1);

i=0;
for (i = 0; i < floors; ++i) {
do{
cout << " Enter the number of rooms on floor "<<i+1<<": ";

cin>>rooms[i];


if(rooms[i]<10)
cout<<"Invalid Input. The number of rooms on a floor cannot be lesser than 10";
}while(rooms[i]<10);

total_rooms+=rooms[i];

cout << "Enter the number of rooms occupied: ";
cin>>filled[i];
total_filled+=filled[i];
}

cout << " Total Number of Rooms in the hotel: "<< total_rooms;
cout << " Number of rooms occupied: "<<total_filled;

cout << " Number of rooms vacant: "<< total_rooms-total_filled;
cout << " Occupancy Rate: "<< total_filled/total_rooms *100<<"%";
cout << " Press Enter To Continue...";
cin.ignore();
cin.get();
return 0;
}