Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm trying to figure out why this code isn't working. The outputs are coming out with the wrong number and I know I'm doing something

I'm trying to figure out why this code isn't working. The outputs are coming out with the wrong number and I know I'm doing something wrong with the logic of the loops. I think I just need a push in the right direction for how to do this correctly.

#include #include #include using namespace std;

int main() { // Declare variables string city; int i; int floors; int rooms; int single_room = 0; int double_room = 0; int king_room = 0; int suite_room = 0;

double number_rooms_on_floor = 0; double total_number_of_rooms = 0; double mininum_number_of_rooms = 0; double floor_with_minimum_number_of_rooms = 0; double hotel_income = 0; double total_number_of_occupied_rooms = 0; double occupied_room = 0; double total_number_of_uncoppied_rooms = 0; double the_rate_of_occupancy = 0; double total = 0.0; double income = 0;

//Declare prices for rooms const int Single_Room_Price_Per_Night = 60; const int Double_Room_Price_Per_Night = 75; const int King_Room_Price_Per_Night = 100; const int Suite_Room_Price_Per_Night = 150;

//Display the name of hotel cout << "========================================================" << endl; cout << setw(25) << "BlueMont Hotel" << endl; cout << "========================================================" << endl;

//Input Validation //Ask user to type a location cout << "Enter the location of this hotel chain: " << endl; cin >> city;

//Ask user to choose a number of floors of the hotel cout << "Enter total number of floors of the hotel (1-5): " << endl; cin >> floors;

while (floors < 1 || floors > 5) { cout << "ERROR: number of floors should be between 1 and 5 !! Please try again." << endl; cout << "Enter total number of floors of the hotel: " << endl; cin >> floors; cout << ' '; }

for (i = 0; i < floors; i++) {

//Ask user to type a total number of rooms of the hotel cout << "Enter total number of rooms in the " << (i + 1) << "th floor: " << endl; cin >> rooms; total_number_of_rooms += rooms;

while (rooms < 0 || rooms > 30) { cout << "ERROR: number of rooms should be between 0 and 30 !! Please try again." << endl; cout << "Please enter total number of rooms in the " << (i + 1) << "th floor: " << endl; cin >> rooms; }

//Get SINGLE rooms on x th floor cout << " How many SINGLE rooms are accupied in the " << (i + 1) << "th floor: " << endl; cin >> single_room; while (single_room < 0 || single_room > 30) { cout << "number of rooms should be between 1 and 30 !! Please try again." << endl; cout << " How many SINGLE rooms are accupied in the " << (i + 1) << "th floor: " << endl; cin >> single_room; }

//Get DOUBLE rooms on x th floor cout << " How many DOUBLE rooms are accupied in the " << (i + 1) << "th floor: " << endl; cin >> double_room; while (double_room < 0 || double_room > 30) { cout << "number of rooms should be between 0 and 30 !! Please try again." << endl; cout << "Enter total number of rooms in the " << (i + 1) << "th floor: " << endl; cin >> double_room; }

// Get King rooms on x th floor cout << " How many KING rooms are accupied in the " << (i + 1) << "th floor: " << endl; cin >> king_room; while (king_room < 0 || king_room > 30) { cout << "number of rooms should be between 0 and 30 !! Please try again." << endl; cout << "Enter total number of rooms in the " << (i + 1) << "th floor: " << endl; cin >> king_room; }

// Get SUITE rooms on x th floor cout << " How many SUITE rooms are accupied in the " << (i + 1) << "th floor: " << endl; cin >> suite_room; while (suite_room < 0 || suite_room > 30) { cout << "number of rooms should be between 0 and 30 !! Please try again." << endl; cout << "Enter total number of rooms in the " << (i + 1) << "th floor: " << endl; cin >> suite_room; } cout << ' ';

// Calculations: Hotel Income, Total number of rooms, Total number of occupied rooms, Total number of Unoccupied rooms, // Occupancy rate.

//Hotel income hotel_income = income + (Single_Room_Price_Per_Night * single_room) + (Double_Room_Price_Per_Night * double_room) + (King_Room_Price_Per_Night * king_room) + (Suite_Room_Price_Per_Night * suite_room);

//Total number of occupied rooms total_number_of_occupied_rooms = rooms - single_room + double_room + king_room + suite_room;

// Total number of uncoppied_rooms total_number_of_uncoppied_rooms = rooms - total_number_of_occupied_rooms;

//Total number of rooms total_number_of_rooms += rooms;

// occupancy rate the_rate_of_occupancy = (total_number_of_occupied_rooms / rooms) * 100.0;

}

// Display to the user the price list cout << "==================================================================================== " << endl; cout << setw(45) << "BlueMont Hotel located in " << city << endl; cout << ' '; cout << setw(55) << " TODAY'S ROOM RATES " << endl; cout << ' '; cout << setw(20) << "Single Room" << setw(20) << "Double Room" << setw(20) << "King room" << setw(20) << "Suite Room" << endl; cout << ' '; cout << setw(20) << "60" << setw(20) << "75" << setw(20) << "100" << setw(20) << "125" << endl; cout << "==================================================================================== " << endl; //Display to the user calculation results cout << setw(25) << "Hotel income: " << setw(15) << "$" << hotel_income << endl; cout << setw(25) << "Total # of rooms: " << setw(15) << total_number_of_rooms << endl; cout << setw(25) << "Total # Occupied Rooms: " << setw(15) << total_number_of_occupied_rooms << endl; cout << setw(25) << "Total # UnOccupied Rooms: " << setw(10) << total_number_of_uncoppied_rooms << endl; cout << setw(25) << "Occupancy rate" << setw(10) << the_rate_of_occupancy << "%" << endl; cout << ' ';

mininum_number_of_rooms = total_number_of_rooms; for (i = 1; i < floors; i++) { if (total_number_of_rooms < mininum_number_of_rooms) mininum_number_of_rooms = (i + 1);

} cout << floor_with_minimum_number_of_rooms << "th floor with " << mininum_number_of_rooms << "rooms has the least # of rooms" << endl;

return 0; } Project Description The BlueMont chain hotels have 4 different types of room: Single room: $60/night Double room: $75/night King room: $100/night Suite room: $150/night The size of the hotel chains in different locations may be different in terms of the number of floors and the type and the number of rooms on each floor. You are required to write a program that calculates the occupancy rate and the total hotel income for one night and displays this information as well as some other info

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

Python - position of chess board identified by letter and number

Answered: 1 week ago

Question

What is are four types of ARTS?

Answered: 1 week ago

Question

What is multiple outcomes design? Explain.

Answered: 1 week ago