60 745
Assignments Done
Successfully Done
In April 2018

Answer to Question #5835 in C++ for haruna

Question #5835
write a program that calculates the occupancy rate of a hotel. the program should start by asking the user how many floors the hotel has. a loop should then iterate once for each floor. in each iteration, the loop should ask the user the number of rooms on the floor and how many of them are occupied. after all the iterations, the program should display how many rooms the hotel has, how many of them are occupied, how many of them are unoccupied, and the percentage of rooms that are occupied . the percentage may be calculated by deviding the numbers of rooms occupied by the number of rooms.
INPUT VALIDATION: do not accept a value less than 1 for the number of floors.
Expert's answer

#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

double percentage;
int i, rooms, totalrooms=0, occupied, totaloccupied=0;

void count(){
int numberoffloors;
cout<<"Enter the number of floors the hotel has: ";
for (i=1;i<=numberoffloors;i++){
& cout<<"Enter the number of rooms on the "<<i<<" floor:";
& cin>>rooms;
& if (rooms<1){
& while (rooms<1){
& cout<<"The number of rooms should be greater then 1\n";
& cout<<"Enter the number of rooms on the "<<i<<" floor:";
& cin>>rooms;
& }
& }
& totalrooms = totalrooms + rooms;
& cout<<"Enter the number of occupied rooms on the "<<i<<" floor:";
& cin>>occupied;
& totaloccupied = totaloccupied + occupied;
percentage = (double)totaloccupied/(double)totalrooms*100;

void main(){

cout<<"Report:\n:total number of rooms in the hotel: "<<totalrooms<<"\nnumber of occupied rooms: "<<totaloccupied<<"\nnumber of unoccupied rooms: "<<totalrooms-totaloccupied<<"\npercentage of occupied rooms: "<<percentage<<"%.\r\n";


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions