bus ticket booking online pakistan

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>

using namespace std;

const int MAX_SEATS = 50;
bool seats[MAX_SEATS] = {false};

void displayAvailableSeats() {
    cout << "Available Seats: ";
    for (int i = 0; i < MAX_SEATS; ++i) {
        if (!seats[i]) {
            cout << i + 1 << " ";
        }
    }
    cout << endl;
}

int bookSeat() {
    int seatNumber;
    displayAvailableSeats();
    cout << "Enter seat number to book: ";
    cin >> seatNumber;

    if (seatNumber < 1 || seatNumber > MAX_SEATS) {
        cout << "Invalid seat number. Please choose a valid seat." << endl;
        return -1;
    }

    if (seats[seatNumber - 1]) {
        cout << "Seat already booked. Please choose another seat." << endl;
        return -1;
    }

    seats[seatNumber - 1] = true;
    cout << "Seat booked successfully!" << endl;
    return seatNumber;
}

int main() {
    srand(time(0));

    while (true) {
        cout << "1. Book a seat" << endl;
        cout << "2. Exit" << endl;
        cout << "Enter choice: ";

        int choice;
        cin >> choice;

        switch (choice) {
            case 1:
                bookSeat();
                break;
            case 2:
                cout << "Exiting program." << endl;
                exit(0);
            default:
                cout << "Invalid choice. Please enter a valid option." << endl;
        }
    }

    return 0;
}