I was attempting to create a program that would allow a user to enter how many floors a hotel had. After determining that number, it would create a loop for that many floors...
Ex. 3 floors....
Floor 1 has 10 rooms, 5 occupied.
Floor 2 has 10 rooms, 5 occupied.
Floor 3 has 10 rooms, 5 occupied.
After completed, it would generate that there were a total of 30 rooms. 15 occupied, 15 unoccupied, and an occupany rate of 50%.
My problem occured when I attempted to take the occupied rooms divided by the total amount of rooms, because it generates a small decimal number which C++ regards as 0.
Any help would be greatly appreciated! Thanks!
CODE
#include<iostream>
using namespace std;
void main()
{
int floors;
int room;
int total;
int occu;
int roomtotal = 0;
int occutotal = 0;
int unopen = 0;
int unopen1 = 0;
int occupyRate = 0;
cout<<"How many floors does the hotel have?\n";
cin>>floors;
if (floors <= 0)
{ cout<<"Please enter a number greater than 0. \n";
cout<<"How many floors does the hotel have?\n";
cin>>floors;
}
for (total = 1; total <= floors; total++)
{
cout<<"How many rooms on floor " <<total <<"?" <<endl;
cin>>room;
roomtotal += room;
cout<<"How many of those rooms are occupied? \n";
cin>>occu;
occutotal += occu;
unopen = (room - occu);
unopen1 += unopen;
}
occupyRate = (occutotal/roomtotal)*100;
cout<<"The hotel has a total of " << roomtotal <<" rooms." <<endl;
cout<< occutotal <<" are occupied." <<endl;
cout<< unopen1 <<" are unoccupied." <<endl;
cout<<"The occupancy rate is " <<occupyRate <<".0%" <<endl;
}