Question: C++ Programming So I have a problem with a program that has a logic error. I'm supposed to show the occupancy rate of the hotel

C++ Programming

So I have a problem with a program that has a logic error. I'm supposed to show the occupancy rate of the hotel (suitesTotal divided by suitesAvailable) in percentage form. Missing output formatting aside, my result is always zero no matter how many times I run it. I know this has something to do with the initialization being set to 0, but I have no clue on how to solve it. I've attached my work below. For reference, I'll write out the question too. Please list out what is wrong or what needs to be modified in order to have the proper output. Thank you in advance.

Program Question:

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 hotel. These are floors 10-12 and 14-16 because there is no 13th floor. Solve the problem using a single loop that loops once for each floor. Use a nested loop to validate the value entered is between 0 and 20. After all the iterations, the program should display how many suites the hotel has, how many occupied, and the percentage of them occupied.

I believe I satisfied all of them except displaying the occupancy rate.

My Source Code:

#include "stdafx.h"

#include

#include

using namespace std;

int main()

{

//Variables for suites occupied per floor, total amount available, and an accumulator to get the sum of all the floors

int suites, suitesAvailable = 120, suitesTotal = 0;

cout << "This program calculates the occupancy rate of the 120 suites available on floors 10 through 16." << endl;

cout << "Reminder: This hotel does not have a 13th floor." << endl;

cout << endl;

//For loop to iterate each floor and ask # of occupied suites

for (int count = 10; count <= 16; count++)

{

//If statement to skip 13 in loop

if (count == 13)

{

continue;

}

cout << "Number of suites occupied on Floor " << count << ": ";

cin >> suites;

//While loop for validation (only 20 suites per floor)

while (suites > 20)

{

cout << "There are only 20 suites per floor." << endl;

cout << "Please reenter: ";

cin >> suites;

}

//The accumulator to later be displayed

suitesTotal += suites;

}

cout << endl;

cout << "Number of available suites on floors 10-16: " << suitesAvailable << endl;

cout << "Number of occupied suites on floors 10-16: " << suitesTotal << endl;

cout << "Occupancy Rate: " << ((suitesTotal / suitesAvailable) * 100 ) << 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!