R
Richard
I do no know why the % amount print out as 0 % for the program below. The
operation seems right. Can anyone help. I am new to c++
code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// ask for information
int Floor, Room, Occuppied, TotalRoom =0, TotalOccuppied=0,
TotalUnOccuppied;
int PercentOccuppied;
cout<<"How many floors the hotel has?:";
cin>>Floor;
for (int count=1; count <= Floor; count++)
{
if (count==13)
continue;
cout<<"How many rooms in floor "<<count<<"? : ";
cin>>Room;
TotalRoom +=Room;
cout<<"How many rooms are occuppied? : ";
cin>>Occuppied;
TotalOccuppied +=Occuppied;
}
cout<<"There are "<<TotalRoom<<" rooms in this hotel. "<<endl;
cout<<"There are "<<TotalOccuppied<<" rooms that are occuppied. "<<endl;
TotalUnOccuppied= TotalRoom - TotalOccuppied;
cout<<"There are "<<TotalUnOccuppied<<" rooms that are not
occuppied."<<endl;
PercentOccuppied = TotalOccuppied/TotalRoom;
//cout<<setprecision(2);
//cout.setf(ios::fixed | ios::showpoint);
cout<<"The percent of rooms that are occuppied is "<<PercentOccuppied<<"
%"<<endl;
}
Output
How many floors the hotel has?:2
How many rooms in floor 1? : 50
How many rooms are occuppied? : 5
How many rooms in floor 2? : 50
How many rooms are occuppied? : 5
There are 100 rooms in this hotel.
There are 10 rooms that are occuppied.
There are 90 rooms that are not occuppied.
The percent of rooms that are occuppied is 0 %
Press any key to continue . . .
operation seems right. Can anyone help. I am new to c++
code
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// ask for information
int Floor, Room, Occuppied, TotalRoom =0, TotalOccuppied=0,
TotalUnOccuppied;
int PercentOccuppied;
cout<<"How many floors the hotel has?:";
cin>>Floor;
for (int count=1; count <= Floor; count++)
{
if (count==13)
continue;
cout<<"How many rooms in floor "<<count<<"? : ";
cin>>Room;
TotalRoom +=Room;
cout<<"How many rooms are occuppied? : ";
cin>>Occuppied;
TotalOccuppied +=Occuppied;
}
cout<<"There are "<<TotalRoom<<" rooms in this hotel. "<<endl;
cout<<"There are "<<TotalOccuppied<<" rooms that are occuppied. "<<endl;
TotalUnOccuppied= TotalRoom - TotalOccuppied;
cout<<"There are "<<TotalUnOccuppied<<" rooms that are not
occuppied."<<endl;
PercentOccuppied = TotalOccuppied/TotalRoom;
//cout<<setprecision(2);
//cout.setf(ios::fixed | ios::showpoint);
cout<<"The percent of rooms that are occuppied is "<<PercentOccuppied<<"
%"<<endl;
}
Output
How many floors the hotel has?:2
How many rooms in floor 1? : 50
How many rooms are occuppied? : 5
How many rooms in floor 2? : 50
How many rooms are occuppied? : 5
There are 100 rooms in this hotel.
There are 10 rooms that are occuppied.
There are 90 rooms that are not occuppied.
The percent of rooms that are occuppied is 0 %
Press any key to continue . . .