View Single Post
Old 10-01-2005, 04:40 PM   #8 (permalink)
subodhgupta1
Registered User
 
Join Date: Sep 2005
Posts: 24
subodhgupta1 is on a distinguished road
Cannot Display percentage

Hi,
The program does everything but calculating percentage, please take a look at the code down below:

//---------------------------------------------------------------------------
#include <iostream.h>
#include <iomanip>
#include <cstring>
#include <fstream>
#include <utility>
#include <conio.h>

using namespace std;
//---------------------------------------------------------------------------

#include <iostream>

int main()
{
unsigned int no_floors=0, no_rooms=0, no_op_rooms=0, temp=0;
int no_unop_rooms;
double pert_occ;

while(no_floors < 1 || no_floors > 13)
{
cout << "Enter number of floors in building: ";
cin >> no_floors;
if(no_floors < 1 || no_floors > 13)
cout << "Error please enter 1 or more floors and less than 13" << endl;
}
for(int i=1; i <= no_floors; ++i)
{
if(i == 13)
continue; /* skip 13th floor */
start_over:
cout << "Enter number of rooms on " << i << ". floor: ";
cin >> temp;
if(temp < 10)
{
cout << "Error you should give 10 or more rooms pr. floor" << endl;
goto start_over;
}
no_rooms += temp;
cout << "Enter number of occupied rooms on " << i << ". floor: ";
cin >> temp;
no_op_rooms += temp;
}

// calculating
no_unop_rooms = no_rooms - no_op_rooms;
pert_occ = (no_op_rooms/no_rooms);

//Displaying the results
cout << endl << "Results-------------------"<<endl;
cout << "The total no. of rooms hotel has: " << no_rooms << endl;
cout << "The total no. of occupied rooms hotel has: " << no_op_rooms << endl;
cout << "The total no. of unoccupied rooms hotel has: " << no_unop_rooms << endl;
cout << "The percentage of rooms that are occupied: " << pert_occ << "%" << endl;
cout << endl << endl << endl << "Press Any Key to Continue...";
getch ();
return 0;
}
subodhgupta1 is offline   Reply With Quote