//Devin Scheu CS1A Chapter 5, P. 295, #9
//
/**************************************************************
*
* CALCULATE HOTEL OCCUPANCY RATE
* ____________________________________________________________
* This program determines the total number of rooms, occupied
* rooms, unoccupied rooms, and the occupancy percentage for a hotel.
*
* Computation is based on a loop summing rooms and occupied rooms
* across all floors, with percentage calculated as occupied rooms
* divided by total rooms
* ____________________________________________________________
* INPUT
* numberOfFloors : The number of floors in the hotel
* roomsPerFloor : The number of rooms on each floor
* occupiedRooms : The number of occupied rooms on each floor
*
* OUTPUT
* totalRooms : The total number of rooms in the hotel
* totalOccupied : The total number of occupied rooms
* totalUnoccupied : The total number of unoccupied rooms
* occupancyPercentage : The percentage of rooms occupied
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
//Variable Declarations
int numberOfFloors; //INPUT - The number of floors in the hotel
int roomsPerFloor; //INPUT - The number of rooms on each floor
int occupiedRooms; //INPUT - The number of occupied rooms on each floor
int totalRooms; //OUTPUT - The total number of rooms in the hotel
int totalOccupied; //OUTPUT - The total number of occupied rooms
int totalUnoccupied; //OUTPUT - The total number of unoccupied rooms
double occupancyPercentage; //OUTPUT - The percentage of rooms occupied
//Prompt for Input
cout << "Enter the number of floors in the hotel: ";
cin >> numberOfFloors;
//Input Validation for number of floors
while (numberOfFloors < 1) {
cout << "\nError: Please enter a number greater than or equal to 1: ";
cin >> numberOfFloors;
}
//Initialize Variables
totalRooms = 0;
totalOccupied = 0;
//Calculate Totals for Each Floor
for (int floor = 1; floor <= numberOfFloors; floor++) {
cout << "\nEnter the number of rooms on floor " << floor << ": ";
cin >> roomsPerFloor;
//Input Validation for rooms per floor
while (roomsPerFloor < 0) {
cout << "\nError: Please enter a non-negative number: ";
cin >> roomsPerFloor;
}
cout << "Enter the number of occupied rooms on floor " << floor << ": ";
cin >> occupiedRooms;
//Input Validation for number of occupied rooms
while (occupiedRooms < 0 || occupiedRooms > roomsPerFloor) {
cout << "\nError: Please enter a number between 0 and " << roomsPerFloor << ": ";
cin >> occupiedRooms;
}
totalRooms += roomsPerFloor;
totalOccupied += occupiedRooms;
}
//Calculate Unoccupied Rooms and Occupancy Percentage
totalUnoccupied = totalRooms - totalOccupied;
occupancyPercentage = (static_cast<double>(totalOccupied) / totalRooms) * 100;
//Output Result
cout << "\n";
cout << left << setw(25) << "Total Rooms:" << right << setw(15) << totalRooms << endl;
cout << left << setw(25) << "Occupied Rooms:" << right << setw(15) << totalOccupied << endl;
cout << left << setw(25) << "Unoccupied Rooms:" << right << setw(15) << totalUnoccupied << endl;
cout << left << setw(25) << "Occupancy Percentage:" << right << setw(15) << occupancyPercentage << "%" << endl;
return 0;
} //end of main()