Loop with Nested If Problem

Hello, I am trying to do a program that involves loops and a nested if.
The user needs to input a hotel specification, and if it meets the criteria to ask further questions regarding.
If the user enters the incorrect number, it goes back to the previous question and asks it again.
In this specific problem, the user will enter the location of the hotel.
Then they will enter the amount of levels the hotel has, which needs to be between 1 and 5.
Then they will enter the amount of rooms that are occupied for single, double, king and suites.
The questions about occupied rooms will go from 1 to the amount of levels the user said the hotel has, in a loop until complete.
The problem I am having is that the only question that is being asked is about the Single rooms, the first if on the program below.
Can anyone point me to what am I doing wrong?

Thank you in advance!


#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
int main()
{
// Constants for hotel
const int single_room = 60;
const int double_room = 75;
const int king_room = 100;
const int suite_room = 150;

int min_floors = 1;
const int max_floors = 5;
const int min_rooms = 1;
const int max_rooms = 30;

int number_floors;
int single_rooms;
int double_rooms;
int king_rooms;
int suite_rooms;

//variables with user input

int total_floors;
string location;


cout << "==================================" << endl;
cout << " Hotel" << endl;
cout << "==================================" << endl;
cout << "\nEnter the location of this hotel chain : ";
cin >> location;


do {
cout << "\nEnter total number of floors of the hotel : ";
cin >> number_floors;



if (number_floors < min_floors || number_floors > max_floors)
{
cout << "\nNumber of floors should be between 1 and 5! Please, try again.\n";

}
else
{
do {


if (number_floors > min_floors || number_floors < max_floors)
{
cout << "\nHow many SINGLE rooms are occupied in the " << min_floors << "th floor: ";
cin >> single_rooms;
}
else if (single_rooms < min_rooms || single_rooms > max_rooms)
{
cout << "\nNumbers of rooms should be between 1 and 30! Please, try again.";

}

else if (single_rooms > min_rooms || single_rooms < max_rooms)
{
cout << "\nHow many DOUBLE rooms are occupied in the " << min_floors << "th floor: ";
cin >> double_rooms;
}
else if (double_rooms < min_rooms || double_rooms > max_rooms)
{
cout << "\nNumbers of rooms should be between 1 and 30! Please, try again.";
}






else if (double_rooms > min_rooms || double_rooms < max_rooms)
{
cout << "\nHow many KING rooms are occupied in the " << min_floors << "th floor: ";
cin >> king_rooms;
}
else if (king_rooms < min_rooms || king_rooms > max_rooms)
{
cout << "\nNumbers of rooms should be between 1 and 30! Please, try again.";
}


else if (king_rooms > min_rooms || king_rooms < max_rooms)
{
cout << "\nHow many SUITE rooms are occupied in the " << min_floors << "th floor: ";
cin >> suite_rooms;
}
else if (suite_rooms < min_rooms || suite_rooms > max_rooms)
{
cout << "\nNumbers of rooms should be between 1 and 30! Please, try again.";
}


{
min_floors++;
}
}

while (true);
}
} while (true);

system("pause");
return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>

int get_bounded_int( std::string prompt, int min_value, int max_value )
{
    std::cout << prompt << " [" << min_value << '-' << max_value << "]? " ;

    int value ;
    if( std::cin >> value ) // if the user entered a number
    {
        if( value >= min_value && value <= max_value ) return value ;
        else std::cout << "value is out of range. try again\n" ;
    }
    else // non numeric input
    {
        std::cout << "input is not an integer. try again\n" ;
        std::cin.clear() ; // clear the failed state
        std::cin.ignore( 1000, '\n' ) ; // throw the bad input away
    }

    return get_bounded_int( prompt, min_value, max_value ) ; // try again
}

int main()
{
    std::string location ;
    std::cout << "Enter the location of this hotel chain : " ;
    std::getline( std::cin, location ) ; // std::getline allows spaces to be part of the location

    const int num_floors = get_bounded_int( "enter number of floors", 1, 5 ) ;

    const int min_rooms = 0 ;
    const int max_rooms = 30 ;

    for( int i = 0 ; i < num_floors ; ++i )
    {
        const std::string floor = std::to_string(i+1) ;
        std::cout << "\nfloor #" << floor << "\n-------\n" ;

        const int NUM_ROOM_TYPES = 4 ;
        const std::string room_type[NUM_ROOM_TYPES] = { "SINGLE", "DOUBLE", "KING", "SUITE" } ;
        int num_rooms[NUM_ROOM_TYPES] ;
        
        for( int j = 0 ; j < NUM_ROOM_TYPES ; ++j )
        {
              num_rooms[j] = get_bounded_int( "how many " + room_type[j] + " rooms are occupied in floor #" + floor,
                                               min_rooms, max_rooms ) ;
        }

        // if required
        const int num_single_rooms = num_rooms[0] ;
        const int num_double_rooms = num_rooms[1] ;
        const int num_king_rooms = num_rooms[2] ;
        const int num_suite_rooms = num_rooms[3] ;

        // ...
    }
}
Thank you.
Topic archived. No new replies allowed.