fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main() {
  6. int numFloors;
  7. int numRooms;
  8. int numOccupied;
  9. int totalRooms=0;
  10. int totalOccupied=0;
  11. int vacantRooms;
  12. double occupiedPCT;
  13.  
  14.  
  15. cout << "Enter number of floors in the hotel\n";
  16. cin >> numFloors;
  17. while (numFloors < 1)
  18. {
  19. cout << "Only enter number that is 1 or greater\n";
  20. cin >> numFloors;
  21. }
  22.  
  23. for (int i = 1; i <= numFloors; i ++)
  24. {
  25. cout << "How many rooms in the floor num " << i << endl;
  26. cin >> numRooms;
  27. while (numRooms < 10)
  28. {
  29. cout << "Only enter number of rooms that is 10 or greater\n";
  30. cin >> numRooms;
  31. }
  32. cout << "How many rooms are occupied in the floor num " << i << endl;
  33. cin >> numOccupied;
  34.  
  35. totalRooms += numRooms;
  36. totalOccupied += numOccupied;
  37. }
  38. vacantRooms = totalRooms - totalOccupied;
  39. occupiedPCT = (static_cast<float>(totalOccupied)/ totalRooms) * 100;
  40.  
  41. cout << "Total Rooms : " << totalRooms << endl;
  42. cout << "Total Occupied Rooms " << totalOccupied << endl;
  43. cout << "Number of Vacant Rooms : " << vacantRooms << endl;
  44. cout << fixed << setprecision(2) ;
  45. cout << "Percentage of Occupied Rooms is : " << occupiedPCT <<"%"<< endl;
  46. return 0;
  47. }
Success #stdin #stdout 0s 5284KB
stdin
2
15
10
30
15
stdout
Enter number of floors in the hotel
How many rooms in the floor num 1
How many rooms are occupied in the floor num 1
How many rooms in the floor num 2
How many rooms are occupied in the floor num 2
Total Rooms : 45
Total Occupied Rooms 25
Number of Vacant Rooms : 20
Percentage of Occupied Rooms is : 55.56%