Write a program that calculates the occupancy rate of the 12
Write a program that calculates the occupancy rate of the 120 suites (20 per floor) located on the top 6 floors of a 15-story luxury hotel. These floors are 10-12 and 14-16 because, like many hotels, there is no 13th floor. Solve the problem by using a single loop that loops once for each floor between 10 and 16 and, on each iteration, asks the user to input the number of suites occupied on that floor. Note that when it is on the iteration for floor 13, no input should be taken. After all the iterations, the program should display how many suites the hotel has, how many of them are occupied, and what percentage of them are occupied. NOTE: Input validation should use loops and NOT if/else
Solution
/**
C++ program that prompts user to enter number of rooms occupied in each
floor from floor =10 to 16. and then calculate total occupied
and unoccupied and rate of occupency to console
*/
//hoteloccupency.cpp
#include<iostream>
using namespace std;
int main()
{
int suites = 120,
totaloccupied=0,
totalRooms = 120,
occupied = 0,
unoccupied = 0,
floorCount=16;
int rate;
for (int floor = 10; floor <= floorCount; floor++)
{
if (floor==13)
continue;
cout << \"Enter occupied rooms on \" << floor << \" floor.\ \";
cin >> occupied;
while(occupied>20 || occupied<0)
{
cout<<\"Invalid rooms entered\ \";
cout << \"Enter occupied rooms on \" << floor << \" floor.\ \";
cin >> occupied;
}
totaloccupied += occupied;
unoccupied = totalRooms - totaloccupied;
}
//calcualte occupancy rate
rate=(totaloccupied*100)/totalRooms;
//print total rooms, occupied and unoccupied , rate to console
cout << \"\ \ The hotel has \" << totalRooms << \" rooms.\ \";
cout << occupied << \" rooms are occupied.\ \";
cout << unoccupied << \" rooms are unoccupied.\ \";
cout << rate << \"% of the rooms are occupied.\ \ \";
//pause program output on console
system(\"pause\");
return 0;
}
Sample output:
Enter occupied rooms on 10 floor.
15
Enter occupied rooms on 11 floor.
15
Enter occupied rooms on 12 floor.
15
Enter occupied rooms on 14 floor.
15
Enter occupied rooms on 15 floor.
15
Enter occupied rooms on 16 floor.
15
The hotel has 120 rooms.
15 rooms are occupied.
30 rooms are unoccupied.
75% of the rooms are occupied.

