first time here so I'm sorry if I didn't do something correctly.

I need to find the total number of floors, rooms on each floor, how many empty rooms there are, occupied rooms on each floor, find occupancy rate, and the "Heartbreak Floor". Which has to display the floor with the least amount of occupied rooms.

I have gotten everything to work except the heartbreak floor. I'm not even sure where to start with it. I emailed my instructor about my problem and he hasn't replied yet so I have come here in hopes of finding a way.


Thanks in advance.

#include <iostream>
using namespace std;
int main()

{
int topFloor, count, occupied, rooms, empty;
int totalRoom, totalOcc;
double occRate;

count = 1;

cout << "What is the top Floor? ";
cin >> topFloor;

if(topFloor <= 0)
   cout << "Error";

while (count <= topFloor){
   cout << "How many rooms are on floor " << count << ":";
   cin >> rooms;
   totalRoom = totalRoom + rooms;

   cout << "How many rooms are occupied on floor " << count << ":";
   cin >> occupied;
   totalOcc = totalOcc + occupied;

   count = count + 1;

if (count == 6 || count == 13)
   count = count + 1;
}

empty = totalRoom - totalOcc;
occRate = (totalOcc * 100) / totalRoom;

cout << "The number of rooms in the hotel are " << totalRoom << endl;
cout << "There are " << totalOcc << " rooms occupied in the hotel." << endl;
cout << "There are " << empty << " empty rooms in the heartbreak." << endl;
cout << The Rate of Occupancy is " << occRate << "%" << endl;

//cout << "The heartbreak floor is " << whatever the floor number is << " with " << occupied rooms on that floor << endl;

return 0;
}

Recommended Answers

All 7 Replies

Not bad for a first post! However, you need to start indenting your code. It makes it easier to read and it makes it easier to debug. For example, it appears you are missing a terminting curly brace, which should probably go before this line:

empty = totalRoom - totalOcc;
-------------------------------------------------
You need intialize all variables acting as counters to zero before you try to increment them, otherwise you will have junk for an answer.
------------------------------------------------
You either need to keep track of a variable to hold the current heartbreak floor or you need to keep track of all floors and then when all information entered search all floors for the heartbreak floor.

Yea I must have missed those when typing the code in. I do have a curly brace before empty = ... and I have count initialized at 1. so
count = 1;

As for finding the floor I'm not quite sure how to start it. I've been sitting here trying to figure this out for about an hour now. This can't be as hard as I'm making it to be.

You either need to keep track of a variable to hold the current heartbreak floor or you need to keep track of all floors and then when all information entered search all floors for the heartbreak floor.

How would I store all the floors when the user is inputting how many there are each time the program runs? If you could point me in the right direction I can put that into an if statement and figure out which floor has the least and how many are one that floor.

It's not that hard, once you see it.

First, you have other running counters besides count. They all need to be initialized to zero before you start incrementing them.

Declare a variable of type int called heartbreakfloor and a varaible called percentOccupancyHeartbreakFloor before the while loop. If count == 1, then assign 1 to heartbreakfloor and assign whatever occupancy floor 1 has as to percentOccupancyHeartbreakFloor. If count not equal to 1, then compare occupancy of current floor to percentOccupancyHeartbreakFloor. If current floor less than percentOccupancyHeartbreakFloor, then assign current occupancy to percetOccupancyHeartbreakFloor and current floor number (count) to heartbreakfloor. At end of loop the variables will hold the desired information.

It's not that hard, once you see it.

First, you have other running counters besides count. They all need to be initialized to zero before you start incrementing them.

Declare a variable of type int called heartbreakfloor and a varaible called percentOccupancyHeartbreakFloor before the while loop. If count == 1, then assign 1 to heartbreakfloor and assign whatever occupancy floor 1 has as to percentOccupancyHeartbreakFloor. If count not equal to 1, then compare occupancy of current floor to percentOccupancyHeartbreakFloor. If current floor less than percentOccupancyHeartbreakFloor, then assign current occupancy to percetOccupancyHeartbreakFloor and current floor number (count) to heartbreakfloor. At end of loop the variables will hold the desired information.

I got that to work but now I'm getting extremely weird numbers for occupied rooms empty rooms and occupancy rate
like 2 billion rooms when i told it 4 rooms for each floor.

Try Initialising Totalrooms and Total Occupied to zero first and then run the code.

Try Initialising Totalrooms and Total Occupied to zero first and then run the code.

I did that first and it didn't help any, but i did fix it. Although I'm not sure how. I just rewrote the occrate equation and it worked just fine. Program is working just fine.

thanks for all your help guys.

I'll defiantly be coming back if I have more questions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.