Question: I just realized I need to make this loop through for each floor and get the occupancy rate for the hotel as a whole -

I just realized I need to make this loop through for each floor and get the occupancy rate for the hotel as a whole - not just one floor. The program should start by asking the user how many floors the hotel has. A 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.

What loop would i use to ask this question for each floor? Do i still use the if/else if?

// This is a program that calculates the occupancy rate for a hotel

#include #include #include

using namespace std;

int main() {

int floor = 1; // Number of floors hotel has int floorNumber = 1; // Level of floor int room = 10; // Number of rooms on each floor int occupiedRoom = 0; // Number of occupied rooms float occupancyRate; // Occupancy rate of the hotel

cout << "This program will calculate the occupancy rate for the hotel. "; cout << "First we need some information about the hotel. " << endl; cout << "****************************************************************" << endl;

cout << "How many floors does this hotel have?" << endl; // Ask user how many floors cin >> floor; // User's value of floor

if (floor < 1)

{ cout << "Zero or negative numbers are not allowed. Please enter a positive value. " << endl; // Input Invalidation cin >> floor; // User's value of floor }

else if (floor >= 1) { cout << "Pick a floor number using numbers 1, 2, 3, ... " << endl; // Ask user to choose a floor cin >> floorNumber; // User's value of floor level }

if (floorNumber < 1) { cout << "Zero or negative numbers are not allowed. Please enter a positive value. " << endl; // Input Invalidation cin>> floorNumber; // User's value of floor level }

else if (floorNumber >= 1) { cout << "How many rooms does this floor have?" << endl; // Ask user how may rooms the floor has cin >> room; // User's value of the number of rooms the floor has }

if (room < 10) { cout << "Zero or negative numbers are not allowed. "; cout << "The number of rooms has to be at least 10. "; cout << "Please enter a positive value or a number greater than or equal to 10. " << endl; // Input Invalidation cin >> room; // User's value of the number of rooms the floor has }

else if (room > 9) { cout << "How many rooms on this floor are occupied?" << endl; // Ask user how many rooms on this floor are occupied cin >> occupiedRoom; //User's value of occupied rooms on this floor }

if (occupiedRoom < 1) { cout << "Zero or negative numbers are not allowed. Please enter a positive value. " << endl; // Input Invalidation cin >> occupiedRoom; // User's value of occupied rooms on this floor }

else if (occupiedRoom >= 0) { occupancyRate = occupiedRoom / room; cout << "The occupancy rate for this hotel is " << occupancyRate << "%" << endl; cout << "" << endl; cout << "Thank you for using the Occupancy Rate Calculating Program! Goodbye. " << endl; }

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!