#define NUM_TABLES 15
#define FIRST_SMALL_TABLE 0
#define LAST_SMALL_TABLE 4
#define SMALL_TABLE_SEATS 2
#define FIRST_MEDIUM_TABLE 5
#define LAST_MEDIUM_TABLE 11
#define MEDIUM_TABLE_SEATS 4
#define FIRST_LARGE_TABLE 12
#define LAST_LARGE_TABLE 14
#define LARGE_TABLE_SEATS 8
typedef struct {
int num_seats;
bool available;
} Table;
typedef struct {
char name[50];
char surname[50];
int phone;
int num_people;
int table_number;
} Reservation;
void display_restaurant_status(Reservation reservation[NUM_TABLES], Table table[NUM_TABLES]) {
for(int i = FIRST_SMALL_TABLE; i <= LAST_SMALL_TABLE; i++) {
if(table[i].available == true) {
printf("%d. SMALL(%d): [AVAILABLE]\n", i + 1, SMALL_TABLE_SEATS);
} else {
printf("%d. SMALL(%d): [OCCUPIED]\n", i + 1, SMALL_TABLE_SEATS);
}
}
for(int i = FIRST_MEDIUM_TABLE; i <= LAST_MEDIUM_TABLE; i++) {
if(table[i].available == true) {
printf("%d. MEDIUM(%d): [AVAILABLE]\n", i + 1, MEDIUM_TABLE_SEATS);
} else {
printf("%d. MEDIUM(%d) [OCCUPIED]\n", i + 1, MEDIUM_TABLE_SEATS);
}
}
for(int i = FIRST_LARGE_TABLE; i <= LAST_LARGE_TABLE; i++) {
if(table[i].available == true) {
printf("%d. LARGE(%d): [AVAILABLE]\n", i + 1, LARGE_TABLE_SEATS);
} else {
printf("%d. LARGE(%d): [OCCUPIED]\n", i + 1, LARGE_TABLE_SEATS);
}
}
}
int check_availability(Table table[NUM_TABLES], int num_people) {
int availability_index = -1;
}``` i need help with
```c
int check_availability(Table table[NUM_TABLES], int num_people) {
int availability_index = -1;
}```
I NEED TO PRINT THIS ---> ""Output: number of smallest free table with enough seats, -1 if no suitable table
free""
#HELP WITH check_availability
5 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
in theory, for example, if I insert 2 people and the number of tables with 2 people are full (small tables) then maybe the medium ones are available, if not even the medium ones then the large ones.
Just iterate over all Table::available tables and pick the one with the smallest Table::num_seats which also is smaller than num_people. If there isn't one - return -1
!solved