Page 1 of 1

## 5 Replies - 485 Views - Last Post: 23 October 2019 - 04:33 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=417640&amp;s=ea43466e8690d9013995e1bdc0113d16&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 beginnerC++

Reputation: 0
• Posts: 12
• Joined: 14-August 19

Posted 22 October 2019 - 04:30 PM

```#include <iostream>
using namespace std;
int main () //program begins with a main function.
{
//Declare variable
int const MAX_SUITES=120;

int suitesonfloor,occupiedsuites = 0;
double percentoccupied;

//loop through each floor
for ( int i = 10; i<=16; i++)
{
if (i == 13)//13th floor does not exist, so skip it
{
continue;
}
do //validate there are 0 -20 suites on floor
{
cout << " Enter the number of suites on floor " << i << " : ";
cin >> suitesonfloor
}while( suitesonfloor < 0 || suitesonfloor >20 );

occupiedsuites = occupiedsuites + suitesonfloor; // Add suit per floor on total

}
//set percentage and cast to double
percentoccupied (static_cast <double> (occupiedsuites))/ MAX_SUITES * 100;

//Display results
cout << "\nTotal suites in the hotel : " << MAX_SUITES <<std :: endl
cout << " Total suites occupied in hotel : " << occupiedsuites << std ::endl
cout << " Percentage of suites occupied : " << percentoccupied << " \% " <std:: endl;

return 0;
}
```

Hi. i am trying to solve this for homework but i am quite confused. can someone help me out please? I AM STUCK

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 are floors 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. 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.

Input validation: Do not accept a value less than 0 or more than 20 for the number of suites occupied on a given floor

Is This A Good Question/Topic? 0

### #2 modi123_1

• Suitor #2

Reputation: 15357
• Posts: 61,571
• Joined: 12-June 08

Posted 22 October 2019 - 04:48 PM

### #3 beginnerC++

Reputation: 0
• Posts: 12
• Joined: 14-August 19

Posted 22 October 2019 - 04:54 PM

@modi123_1 the program is not running. i dont know where the mistake is . Plus i dont know where to put the condition of input validation. I posted what the program needs to do. I tried everything but cant find mistake

### #4 modi123_1

• Suitor #2

Reputation: 15357
• Posts: 61,571
• Joined: 12-June 08

Posted 22 October 2019 - 06:22 PM

The instructions indicate one loop, but you have a second. Punt that do-while.

### #5 Skydiver

• Code herder

Reputation: 7135
• Posts: 24,239
• Joined: 05-May 12

Posted 22 October 2019 - 06:47 PM

The instructions merely say don't accept invalid values for computation. It doesn't say that you need to keep prompting until valid input is entered. This will then let you use just a single loop.

### #6 TightCoderEx

Reputation: 1
• Posts: 3
• Joined: 01-December 12

Posted 23 October 2019 - 04:33 PM

You were very close, close enough to warrant this example. There is a couple of problems with this code, so let's see if you can come up with a fix. Technically this is a single loop and that there is another loop to trap errors is coincidental in my mind. In any event, you had in your code so I included the nested loop.

```#include <iostream>

using namespace std;

const int MAX_SUITES = 120;

int main (void) {
int totalSuites {0};
int	occupied {0};

// This prompting is for a VT100 compatible terminal on LINUX.
cout << "\033[2J\033[4;16HEnter occupied suites for each floor]\n\n";

for (int floor = 10; floor < 17; floor++) {
if (floor == 13)
continue;

cout << "\n\t\tFloor #" << floor << "\t--> ";

do {
cin >> occupied;
if (occupied > 0 && occupied <= 20) {
totalSuites += occupied;
break;
}
cout << "\t\t\t\t--> ";
} while (1);
}

cout << "\n\n\tTotal   suites = " << MAX_SUITES << endl;
cout << "\tTotal occupied = " << totalSuites << endl;
cout << "\tVacancy   rate = " <<
((double) totalSuites/(double) MAX_SUITES) * 100 << "%" << endl;

return EXIT_SUCCESS;
}

```

This post has been edited by TightCoderEx: 23 October 2019 - 04:41 PM