reservation function

the function is suppose to do this
reserveSmoking – has an int parameter. The value passed to this parameter is the location of the seat to be reserved in the smoking section of the airplane. Please note that only the first 5 seats in the plane can be used for smoking customers (0-4) - the other 5 seats (5-9) cannot be used. The function returns an int with the same value as the seat number that was reserved (essentially, it returns the index of the array where the seat was reserved). However, if the requested seat number is already occupied, then the function must return -1.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
i have this 
i dont think my code is correct 
for (int i = 0; i < seats; i++) {
         reduceAvailableSeats();
        cout << "Please select from one(0) to four(4): ";
        cin >> num;
        while (num < 0 || num > 4) {
            cout << "Please select from one(0) to four(4): ";
            cin >> num;
        }

        if (plane[i] == i) { //checking if number entered matches the index

            return num; //return index

        }

    }
    return -1; //if seat is not available return -1 


i should also call reduce available seats in this function


reduceAvailableSeats – this function should be called every time a reservation is successfully made in either the smoking or non-smoking section of the plane. It should reduce the value of seats by 1 but also ensure that its value never goes below 0.



Last edited on
> if (plane[i] == i) { //checking if number entered matches the index
the number entered is stored in the `num' variable
your check does not involve `num' at all
Topic archived. No new replies allowed.