HELP : change the array in a function.

hi. i'm writing a hotel room reservation program and i'm having some problems. i have declared 5 arrays with the type of bool and set all of them to FALSE.


1
2
3
4
5
6
bool standard [10] = {false, false, false, false, false, false, false, false, false, false};
    bool moderate [10] = {false, false, false, false, false, false, false, false, false, false};
    bool superior [10] = {false, false, false, false, false, false, false, false, false, false};
    bool deluxe   [10] = {false, false, false, false, false, false, false, false, false, false};
    bool suite  [5] = {false, false, false, false, false};
    bool studio [5] = {false, false, false, false, false};


these arrays represent different room types and i have put them in my main. now, i'm writing a function in order to check the availability of the rooms (to see if they're booked or not). i pass the arrays to a function and then try to do this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void checkAvail (string indate, string outdate, int rooms, char type, bool arg1[], bool arg2[], bool arg3[], bool arg4[], bool arg5[], bool arg6[])

{
    
    if (type == '1')
    {
        int i = 0;
        while (i <= rooms)
        {
            arg1 [i] = {true};
            i++;
            
        }    

    }

}



the compiler won't accept the statement of the WHILE loop. i also tried using FOR and that didn't work either. any help?

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>
using namespace std;




void checkAvail (string indate, string outdate, int rooms, char type, bool arg1[], bool arg2[], bool arg3[], bool arg4[], bool arg5[], bool arg6[])

{
    
    if (type == '1')
    {
        int i = 0;
        while (i <= rooms)
        {
            arg1 [i] = {true};
            
        }    

    }

}

int main ()

{
  
    bool standard [10] = {false, false, false, false, false, false, false, false, false, false};
    bool moderate [10] = {false, false, false, false, false, false, false, false, false, false};
    bool superior [10] = {false, false, false, false, false, false, false, false, false, false};
    bool deluxe   [10] = {false, false, false, false, false, false, false, false, false, false};
    bool suite  [5] = {false, false, false, false, false};
    bool studio [5] = {false, false, false, false, false};

    string checkInDate; 
    string checkOutDate;
    char type;
    int rooms;
    
    
    cout << "welcome" << '\n';
    cout << "please enter check-in date: " << '\n';
    cin >> checkInDate;
    
    cout << "please enter check-out date: " << '\n';
    cin >> checkOutDate;
    
    cout << "how many rooms you want?: " << '\n';
    cin >> rooms;
    
    cout << "please choose the type of room you want: " << '\n';
    cout << "1 for STANDARD, 2 for MODERATE, 3 for SUPERIOR, 4 for DELUXE, 5 for SUITE and 6 for STUDIO: " << '\n';
    cin >> type;
    
    checkAvail (checkInDate, checkOutDate, rooms, type, standard, moderate, superior, deluxe, suite, studio);
    
    
}
Last edited on
arg1[i] = {true}; should be arg1[i] = true;
I don't think that that makes any difference @Peter87.

Can you be more specific about
the compiler won't accept the statement of the WHILE loop
as my compiler does not indicate any problem.
Last edited on
closed account (zb0S216C)
First, your array initialization lists are unnecessary. Simply doing this: = {0} will cause the compiler to assign the value of 0 (implicitly converted to a bool) to each of the Boolean values in the array.

In the checkAvail() function, since you know the length of each array beforehand, I would replace the arg1 to arg6 parameters with references to arrays, like so:

1
2
3
4
5
void checkAvail(..., bool(&A1)[10], ..., bool(&A6)[5])
{
    if(A1[0])
        // ...
}

I also recommend using symbolic names for your array lengths; preferably enumerations or const ints. Why? Numeric literals aren't self-descriptive; that is, they don't signify their use in the current code.

Wazzak
Topic archived. No new replies allowed.