Help with Hotel Occupancy Program?

Hi I am trying to write a program to determine hotel occupancy. I am STUCK in my loop!!!! What is wrong with this code?!

The program should begin by asking for the number of floors. The program should then iteratively ask for the total number of rooms on each floor and how many of those are currently occupied. After all the floor info is entered, the program displays how many total rooms the hotel has, how many are occupied, how many are unoccupied and the percentage of rooms that are occupied. Also print which floor is the Heartbreak floor (floor with most empty rooms)

1. Use a for loop for looping control structure
2. Validate that the number of floors is at least 1. Use a while loop to validate the input and display an error message.
3. Each floor must have at least 10 rooms.
4. The number of rooms occupied for each floor must not exceed the number of room on the floor and cannot be less than 0. Display an error message.
5. Skip the second floor completely
6. Display the percentage value in standard percent format with one decimal place.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <string>
using namespace std;

int main()
{
    //Declaration Section
    int numfloors, floor, hbfloor, hbempty, occurate, numrooms, emptyrms, fullrms, totrooms, totfullrms, totemptyrms;

    //Input Section
    cout << "How many floors does the hotel have? ";
    cin >> numfloors;

    winner = -100;
   
    for (floor = 1; floor <= numfloors; floor++)
        {   
            floor++;
            numfloors+=floor;
            cout << " " << endl;
            cout << "How many rooms are on floor " << floor << "? ";
            cin >> numrooms; 
            cout << "How many of those rooms are occupied? ";
            cin >> fullrms;
            cout << " " << endl;
            numrooms+=totrooms;
            if (floor = 2)
                continue;
            
            if (emptyrms > winner)
                {
                    winner = emptyrms;
                    winfloor = floor;
                }
        }
        while (numfloors < 1)
            {
                cout << "Invalid number of floors, please try again: ";
                cin >> numfloors;
            }
        while (numrooms < 10)
            {
                cout << "Invalid number of rooms, please try again: ";
                cin >> numrooms;
            }
        while (fullrms > numrooms || fullrms < 1)
            {   
                cout << "Invalid number of rooms, please try again: ";
                cin >> fullrms;
            }
        occurate = totfullrms / totrooms;

 
       
    //Output Section
    cout << " " << endl;
    cout << "The hotel has a total of " << totrooms << " rooms." << endl;
    cout << totfullrms << " are occupied." << endl;
    cout << totemptyrms << " are empty." << endl;
    cout << "The occupancy rate is " << occurate << "%" << endl;
    cout << "The heart break floor is " << hbfloor << " with " << hbempty << " empty rooms." << endl;

system ("pause");
return 0;
}
Last edited on
Line 18: Why are you incrementing floor? Your for loop does that for you.
Line 19: Why are you adding floor to numfloors? numfloors shouldn't change.
Lines 36-40 are in the wrong place. You should edit the value BEFORE you us it at line 16.
Line 26: Where is totrooms initialized? Why are you changing numrooms which you just got from the user?
Lines 41-45 are in the wrong place. You should edit numrooms BEFORE you use it.
Line 27: The if statement is misplaced. I would presume that "skip the second floor" means not to ask how many rooms are on the second floor.
Lines 46-50 are misplaced. You should edit check fullrms before you use it.
Line 30: Where is emptyrms calculated?
Line 61: Where are hbfloor and hbempty values set?
Last edited on
1
2
for(floor = 1; floor <= numfloors; floor++) {
	floor++;


floor is assigned the value of 1, then floor is increased, and then again once the loop restarts.

line 27:
if(floor = 2) {

You're assigning 2 to floor.
Topic archived. No new replies allowed.