i have an assignment to make a bus reservation system that will return in main 35 times and increase the ticket number,using function arrays,and looping and can anyone help me ive been doing this assignment for 3 weeks now and i cant do it.

Dani AI

Generated

A clean, testable design is to model the bus as an array of 35 slots (index 0..34), store 0 for free or the ticket number when booked, and keep a single ticket counter that is passed to the booking function (by pointer or stored globally). Small functions make the program easy to reason about: init_seats, book_seat (scan for first free slot, set it to next_ticket++, return seat index or -1), and print_ticket. Calling book_seat repeatedly from main inside a loop is the usual way to "do the booking 35 times" rather than trying to use multiple return statements in main.

If the phrase "function arrays" really means an array of function pointers (rather than "use functions and arrays"), C does support arrays of function pointers for functions that share the same signature; that pattern is useful when dispatching actions by index (for example to replace a large switch). (cs-fundamentals.com)

Here is a compact example showing the core idea (seats stored in an int array, booking function called repeatedly and ticket number incremented):

#include <stdio.h>
#define MAX_SEATS 35

void init_seats(int seats[], int n) {
    for (int i = 0; i < n; ++i) seats[i] = 0;
}

int book_seat(int seats[], int n, int *next_ticket) {
    for (int i = 0; i < n; ++i) {
        if (seats[i] == 0) {
            seats[i] = (*next_ticket)++;
            return i;
        }
    }
    return -1;
}

void print_ticket(int seat_index, int ticket) {
    printf("Ticket %d -> Seat %d\n", ticket, seat_index + 1);
}

int main(void) {
    int seats[MAX_SEATS];
    int next_ticket = 1;
    init_seats(seats, MAX_SEATS);
    for (int i = 0; i < MAX_SEATS; ++i) {
        int idx = book_seat(seats, MAX_SEATS, &next_ticket);
        if (idx == -1) break;
        print_ticket(idx, seats[idx]);
    }
    return 0;
}

Common pitfalls and notes: watch off-by-one errors when mapping array index to human seat numbers (add 1 for display); ensure the ticket counter is incremented exactly once per booking; avoid unsafe input routines (use size-limited reads for names); test with a smaller MAX_SEATS while debugging. The earlier replies in this thread are on point: asked for code to debug, and ’s check about whether "35" means seat count is relevant — the example above assumes 35 seats.

Recommended Answers

All 7 Replies

Member Avatar for Member #46692

Please post your code and a more detailed explanation of your task.

bus reservation project

commented: For bumping old threads and then not even posting a question -1
commented: idiotic repeated bumping of a dead thread. -7

can u help me

So?

can u help me

Please post your code and a more detailed explanation of your task.

can u help me

commented: Not until you learn how to ask a question. -6

just post your code and show whats wrong with it and what do you mean by return 35 times ? you mean there will be 35 seats in the bus ? and max booking is not more than 35 seats?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.