Rate calculation

I got the entire program to work. However, for some reason, I can not get the program to calculate the occupancy rate. It continues to display 0.00. Any help is greatly, greatly appreciated. Here is the code:

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main ()

{
int floors = 0;
int availableRooms = 0;
int maxValue; // To store maximum number of floors
int totalRooms = 0; //This should be my accumulator for rooms
int totalOccupied = 0; //This should work as accumulator for totalOccupied
float occupancyRate = 0;

//Get the number of floors
cout <<"How many floors are there in this hotel? ";
cin >> maxValue;

//Get the rooms for each floor and accumulate the total
for (floors = 1; floors <= maxValue; floors++)
{
int rooms, taken, occupied=0;
cout <<"Please enter the number of rooms in floor " << floors << ": ";
cin >> rooms;
cout <<"How many of those rooms are occupied? ";
cin >> occupied;
totalOccupied += occupied;
totalRooms += rooms;
availableRooms = (totalRooms-totalOccupied);

}
cout << fixed << showpoint << setprecision(2);
occupancyRate = (totalOccupied / totalRooms);
cout <<"The total number of rooms for this hotel is: "<<totalRooms<<endl;
cout <<"There are" " "<< availableRooms <<" ""available rooms;"<<endl;
cout <<"The occupancy rate for this hotel is:" " " << occupancyRate <<endl;

return 0;

}

dude, occupied and room are integers. int

during the division, the answer calculated as an integer
(it rounds of the answer before Implicit Type Conversion to floats)

make floors and room floats
Last edited on
Topic archived. No new replies allowed.