I am having a hard time with my homework and I was wondering if someone could help.
I have to create a program that uses a while loop to ask questions about a hotel. It first ask the number of the top floor then asks How many rooms are on the floor? and How many of those rooms are occupied?. Then at the end it displays the total number of rooms, the total of occupied rooms, the total of empty rooms, the occupancy rate, and the "Heartbreak floor" which is the floor with the least occupied rooms and the smallest number. Plus the program has to skip floor 6, just like most hotels don't have a floor 13.
My first problem is that I need in invalid option, that does not display the rest of the information when you enter 0. I have gotten it to displays Invaild but it also displays 0 total rooms 0 occupied etc which I don't want.
The second problem is that I have figured out how to display the least rooms occupied with an if < statement but I'm not sure how to display the floor number also.
The third problem is that I'm not sure how to skip floor 6. I tried saying while ((topfloor>=1) && (topfloor != 6)) but this only resulted in the program running once and then stopping.
I think that's all my problems. If anyone could help I would appreciate it. Thanks, SSR
PS I know the occupancy rate looks weird but that was the only way I could get it to display the tenth decimal place, otherwise it would just display 0.
Here is the code:
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int floor = 0;
int highnum = 20000;
double occupancy;
int topfloor, occupiedrooms, rooms, roomtotal, occupiedroomstotal,
emptyrooms;
cout << "What is the number of the top floor? ";
cin >> topfloor;
if (topfloor<1)
cout <<"Invalid number of floors. Please try again."<<endl;
while (topfloor>=1)
{
floor = floor +1;
cout <<"How many rooms are on floor " <<floor <<"? ";
cin >> rooms;
cout <<"How many rooms are occupied? ";
cin >> occupiedrooms;
if (occupiedrooms< highnum)
highnum = occupiedrooms;
roomtotal += rooms;
occupiedroomstotal += occupiedrooms;
emptyrooms = roomtotal-occupiedroomstotal;
topfloor = topfloor - 1;
}
cout << "The hotel has a total of "<< roomtotal <<" rooms."<<endl;
cout << occupiedroomstotal <<" are occupied." <<endl;
cout << emptyrooms <<" are empty." <<endl;
occupancy =(occupiedroomstotal*10000)/roomtotal;
occupancy = occupancy/100;
cout << "The occupancy rate is "
<<setprecision(1)<<showpoint<<fixed<<occupancy <<"%." <<endl;
cout << "The Heartbreak floor is: " <<floor <<" with only " <<highnum <<" occupied rooms." <<endl;
return 0;
}