Any idea why this isn't iterating into the variables?

Keep coming up with 0 for output of all variables, not sure what I'm missing.

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
66
#include <iostream>
using namespace std;
int main()
{
    float occ_rate = 0,
          rooms_occupied = 0,
          total_rooms = 0;

    int rooms,
        num_floors,
        filled_rooms = 0,
        total_occupied = 0,
        unoccupied = 0;

    cout << "Floors in the hotel: ";

    while (!(cin >> num_floors) || (num_floors < 1))
    {
        cout << "Enter a valid number of floors";
                   
    }

    for(int i = 0; i < num_floors; i++)
    {
        {
            cout << "Rooms on floor ";
            cout << (i + 1)<<": ";

            while (!(cin >> rooms))
            

            total_rooms += rooms;
			
            cout << "Rooms occupied: ";
           
		    while (!(cin >> rooms_occupied) || 
                    (rooms_occupied < 1))

             filled_rooms += rooms_occupied;
        }
        
        
    }

    unoccupied = total_rooms - filled_rooms;
    cout << "Total rooms unoccupied = " 
         << unoccupied 
         << endl;

    cout << "Total rooms used = " 
         << filled_rooms 
         << endl;
         
    cout << "Total number of rooms = " 
         << total_rooms 
         << endl;

    occ_rate = (filled_rooms / total_rooms) * 100;
    cout << "Occupancy rate = " 
         << occ_rate 
         << "%." 
         << endl;
    

    return 0;
}
you need ; on the while loops that read the data.
its pushing the next line into the loop where it does not belong, and your whitespace/indents make it hard to spot that.
Last edited on
Thank you, that fixed it
Topic archived. No new replies allowed.