-Write a program that calculates the occupancy rate for a hotel. The program sho
ID: 3698785 • Letter: #
Question
-Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user the mumber of floors the hotel has. . Note, it is traditional that most hotels do not have a thirteenth floor. The loop should then iterate once for each floor. . It should skip the entire thirteenth iteration. In each iteration, the loop should ask the user for the number of rooms on the floor and how many of them are occupied. -After all the iterations, the program should display the number of rooms that the hotel has the number of rooms that have been occupied, the number of rooms that have not been occupied, and the percentage of rooms that are occupied The percentage may be calculated by dividing the number of rooms occupied by the number of rooms - Input Validation: . Do not accept a value less than 1 for the number of floors. . Do not accept a number less than 10 for the number of rooms on a floor.Explanation / Answer
If you have any doubts, please give me a comment..
#include<stdio.h>
int main(){
int floors, total_rooms=0, occupied_rooms=0, not_occupied_rooms=0, i;
printf("Enter Number of floors the hotel has: ");
while(1){
scanf("%d", &floors);
if(floors>0)
break;
printf("Atleast 1 floor available in hotel. Reenter: ");
}
i=1;
int rooms, occ_rooms;
while(i<=floors){
if(i==13){
i++;
continue;
}
printf("Enter number of rooms on the floor %d: ", i);
while(1){
scanf("%d", &rooms);
if(rooms>=10)
break;
printf("Each floor at least have 10 rooms. Reenter: ");
}
total_rooms += rooms;
printf("Enter number of rooms occupied on the floor %d: ", i);
while(1){
scanf("%d", &occ_rooms);
if(occ_rooms<=rooms)
break;
printf("Occupied rooms must be lessthan or equal to total rooms. Reenter: ");
}
occupied_rooms += occ_rooms;
i++;
}
not_occupied_rooms = total_rooms - occupied_rooms;
int j=0;
printf("Number of rooms that the hotel has: %d ", total_rooms);
printf("Number of rooms that have been occupied: %d ", occupied_rooms);
printf("Number of rooms that not occupied: %d ", not_occupied_rooms);
printf("Percentage of rooms that are occupied: %.2lf %% ", (occupied_rooms/total_rooms)*100);
j++;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.