Hello guys....I just have some doubt about C programming...well I have done a lot of functions for airline booking system but im not able to implement the multi dimensional array... I dont get how should I implement it in this problem as the variables are global and they are used in different functions. So below is just a part of where i am blur on how to use the multidimensional array...here im trying to use 4 dimensional array and I get a lot of errors in it....Hope you guys can help me out....Thanks

void menu_PurchaseTicket()
{
	menu_chooseTicket();//a variable is used to store the input here
	menu_ChooseDestination();//a variable is used to store the input here
	menu_ChooseTime();//a variable is used to store the input here
	menu_ViewSeating();//function showing the seats arrangement in rows and columns(5x5)
	menu_ChooseSeat();//a variable is used to store the input here
	
	int seat[cust_TicketClass][cust_Destination][cust_Time][cust_Seat];
	int a,b,c,d;
	for(a=0;a<2;a++)
	{
		if(cust_TicketClass == 0)
			printf("Business Class");
		else
			printf("Economy Class");

		for(b=0;b<2;b++)
		{
			if(cust_Destination == 0)
				printf("Destination: Kuala Lumpur --> Langkawi\n\n");
			else
				printf("Destination: Langkawi --> Kuala Lumpur\n\n");
			
			for(c=0;c<5;c++)
			{
				switch(cust_Time)
				{
					case '1':
						printf("Departure Time: 9.00 a.m\n");

					case '2':
						printf("Departure Time: 11.00 a.m\n");

					case '3':
						printf("Departure Time: 1.00 p.m\n");

					case '4':
						printf("Departure Time: 3.00 p.m\n");

					case '5':
						printf("Departure Time: 5.00 p.m\n");

					default:
						printf("Please enter the correct selection\n\n");

					for(d=0;d<25;d++)
					{
						if(cust_Seat>25 || cust_Seat<0)
							printf("Invalid Seat Number");

						if(cust_Seat>0 || cust_Seat<25)
							seat[cust_TicketClass][cust_Destination][cust_Time][cust_Seat]=1;
					}
				}
			}
		}
	}

You should switch to using a struct to represent your ticket class, destination, seat, and time. . All four of those things are obviously related data. You're only going to cause yourself headache trying to use a 4d array for this purpose, and using a 4d array like that doesn't make sense for your data . Why not create a struct to group the related data and then create an array of structs?

Can you paste the errors you get? And possibly more code?
By the first look I can advise to use pointers instead of int seat[][][][].

#include <stdio.h>
#include <ctype.h>
#include <conio.h>
void mainmenu(void);
void menu_PurchaseTicket(void);
void menu_chooseTicket(void);
void menu_BizClass(void);
void menu_EconomyClass(void);
void menu_DepartureBizKL(void);
void menu_DepartureBizLK(void);
void menu_DepartureEconKL(void);
void menu_DepartureEconLK(void);
void menu_ViewSeating(void);
void menu_ChooseDestination(void);
void menu_ChooseTime(void);
void menu_ChooseSeat(void);

int exit_ViewSeating, cust_TicketClass, cust_Destination, cust_Time, cust_Seat;
char MenuSelect,TicketSelect,BizClassSelect,EconomyClassSelect,ViewSeatingSelect;
main()
{
	mainmenu();
}

//main menu function
void mainmenu()
{
	system("cls");
	//print welcome screen
	printf("\n\t\t\t\t--WELCOME TO--");
	printf("\n\t\t<<<< THALABATHY AIRLINE RESERVATION SYSTEM >>>> \n");

	printf("\n\n\t\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
	printf("\n\t\t\t\t%%%%%% Main Menu %%%%%%%\n");
	printf("\t\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");

	
	
	printf("\n\t\t\t\tP to Purchase Ticket\n");
	printf("\n\t\t\t\tV to View Seating Arrangement\n");
	printf("\n\t\t\t\tQ to Quit the system\n\n");
	printf("\n\n\t\t\t\tPlease enter your choice:");
	fflush(stdin);
	MenuSelect = getchar();
	
	switch(MenuSelect)
	{
		
		case 'P':
		case 'p':
			menu_PurchaseTicket();
			break;
		

		case 'V':
		case 'v':
			
			menu_ViewSeating();
			break;
			

		case 'Q':
		case 'q':
			
			printf("Thank you for choosing Airlines Reservation System");
			break;
		

		default:
			printf("Please enter the correct selection");
			

	}

}

void menu_PurchaseTicket()
{
	menu_chooseTicket();
	menu_ChooseDestination();
	menu_ChooseTime();
	menu_ViewSeating();
	menu_ChooseSeat();
	
	int seat[cust_TicketClass][cust_Destination][cust_Time][cust_Seat];
	int a,b,c,d;
	for(a=0;a<2;a++)
	{
		if(cust_TicketClass == 0)
			printf("Business Class");
		else
			printf("Economy Class");

		for(b=0;b<2;b++)
		{
			if(cust_Destination == 0)
				printf("Destination: Kuala Lumpur --> Langkawi\n\n");
			else
				printf("Destination: Langkawi --> Kuala Lumpur\n\n");
			
			for(c=0;c<5;c++)
			{
				switch(cust_Time)
				{
					case '1':
						printf("Departure Time: 9.00 a.m\n");

					case '2':
						printf("Departure Time: 11.00 a.m\n");

					case '3':
						printf("Departure Time: 1.00 p.m\n");

					case '4':
						printf("Departure Time: 3.00 p.m\n");

					case '5':
						printf("Departure Time: 5.00 p.m\n");

					default:
						printf("Please enter the correct selection\n\n");

					for(d=0;d<25;d++)
					{
						if(cust_Seat>25 || cust_Seat<0)
							printf("Invalid Seat Number");

						if(cust_Seat>0 || cust_Seat<25)
							seat[cust_TicketClass][cust_Destination][cust_Time][cust_Seat]=1;
					}
				}
			}
		}
	}

	
	/*system("cls");
	printf("PLEASE CHOOSE YOUR TICKET CLASS:\n\n");
	printf("B for BUSINESS CLASS SEATS\n\n");
	printf("E for ECONOMY CLASS SEATS\n\n");
	printf("M for RETURN TO MAIN MENU\n\n");
	printf("Please enter your selection -->");
	fflush(stdin);
	TicketSelect = getchar();

	switch(TicketSelect)
	{
		case 'B':
		case 'b':
				menu_BizClass();
				break;
			

		case 'E':
		case 'e':
				menu_EconomyClass();
				break;
			

		case 'M':
		case 'm':
				mainmenu();
				break;
		
		default:
			system("cls");
			printf("Please enter the correct selection");
			menu_PurchaseTicket();
	}*/
}

void menu_chooseTicket()
{
	system("cls");
	printf("Please choose your Tciket Class\n\n");
	printf("1 >> Business Class\n\n");
	printf("2 >> Economy Class\n\n");
	printf("Please enter your selection --> ");
	fflush(stdin);
	scanf("%d",&cust_TicketClass);
	
}

void menu_ChooseDestination()
{
	system("cls");
	printf("Please choose destination\n\n");
	printf("1 >> Kuala Lumpur --> Langkawi\n\n");
	printf("2 >> Langkawi --> Kuala Lumpur\n\n");
	printf("Please enter your selection --> ");
	fflush(stdin);
	scanf("%d",&cust_Destination);
}

void menu_ChooseTime()
{
	system("cls");
	printf("Please choose flight time\n\n");
	printf("1 >> 9  a.m.\n\n");
	printf("2 >> 11 a.m.\n\n");
	printf("3 >> 1  p.m.\n\n");
	printf("4 >> 3  p.m.\n\n");
	printf("5 >> 5  p.m.\n\n");
	printf("Please enter your selection --> ");
	fflush(stdin);
	scanf("%d",&cust_Time);
}

void menu_ChooseSeat()
{
	printf("Please choose your seat --> ");
	scanf("%d",&cust_Seat);
	
}


void menu_BizClass()
{
	system("cls");
	printf("Destination Menu\n");
	printf("A --> Kuala Lumpur to Langkawi\n");
	printf("B --> Langkawi to Kuala Lumpur\n");
	printf("M --> Return to Main Menu\n");
	printf("Please Enter your Selection -->");
	fflush(stdin);
	BizClassSelect = getchar();

	switch(BizClassSelect)
	{
		case 'a':
		case 'A':
			menu_DepartureBizKL();
			break;

		case 'b':
		case 'B':
			menu_DepartureBizLK();
			break;

		case 'M':
		case 'm':
			mainmenu();
			break;

		default:
			system("cls");
			printf("Please enter the correct selection");
			menu_BizClass();
	}



}

void menu_EconomyClass()
{
	system("cls");
	printf("Destination Menu\n");
	printf("A --> Kuala Lumpur to Langkawi\n");
	printf("B --> Langkawi to Kuala Lumpur\n");
	printf("M --> Return to Main Menu\n");
	printf("Please Enter your Selection -->");
	fflush(stdin);
	EconomyClassSelect = getchar();

	switch(EconomyClassSelect)
	{
		case 'a':
		case 'A':
			menu_DepartureEconKL();
			break;

		case 'b':
		case 'B':
			menu_DepartureEconLK();
			break;

		case 'M':
		case 'm':
			mainmenu();
			break;

		default:
			system("cls");
			printf("Please enter the correct selection");
			menu_EconomyClass();
	}
}

void menu_DepartureBizKL()
{
	system("cls");
	printf("Business Class\n");
	printf("Departure Menu\n");
	printf("Destination: Kuala Lumpur --> Langkawi\n");
	printf("A --> 9.00  a.m\n");
	printf("B --> 11.00 a.m\n");
	printf("C --> 1.00  p.m\n");
	printf("D --> 3.00  p.m\n");
	printf("E --> 5.00  p.m\n");
	printf("Please enter your selection --> ");


}

void menu_DepartureBizLK()
{
	system("cls");
	printf("Business Class\n");
	printf("Departure Menu\n");
	printf("Destination: Langkawi --> Kuala Lumpur\n");
	printf("A --> 9.00  a.m\n");
	printf("B --> 11.00 a.m\n");
	printf("C --> 1.00  p.m\n");
	printf("D --> 3.00  p.m\n");
	printf("E --> 5.00  p.m\n");
	printf("Please enter your selection --> ");


}

void menu_DepartureEconKL()
{
	system("cls");
	printf("Economy Class\n");
	printf("Departure Menu\n");
	printf("Destination: Kuala Lumpur --> Langkawi\n");
	printf("A --> 9.00  a.m\n");
	printf("B --> 11.00 a.m\n");
	printf("C --> 1.00  p.m\n");
	printf("D --> 3.00  p.m\n");
	printf("E --> 5.00  p.m\n");
	printf("Please enter your selection --> ");


}

void menu_DepartureEconLK()
{
	system("cls");
	printf("Economy Class\n");
	printf("Departure Menu\n");
	printf("Destination: Langkawi --> Kuala Lumpur\n");
	printf("A --> 9.00  a.m\n");
	printf("B --> 11.00 a.m\n");
	printf("C --> 1.00  p.m\n");
	printf("D --> 3.00  p.m\n");
	printf("E --> 5.00  p.m\n");
	printf("Please enter your selection --> ");


}

void menu_ViewSeating()
{
	int row,col;
	int seats[5][5]={0};
	printf("\t\tSeating In All Flights\n\n");
	printf("\t1\t2\t3\t4\t5\n");
		for (row=0; row<5; row++)
		{
			printf("\n%d", row+1);
			for (col=0; col<5; col++)
			{
				printf("\t%d", seats[row][col]);
			}
		}
	
	
	printf("\n\nNote: Please choose your seat using row and column format.\n\nFor example:To book seat at row 1 column 3 type 13\n\n");
	printf("\n<< Legend >>\n\n");
	printf("\n\nBusiness Class Seats: 11,12,13,14,15\n\n");
	printf("\n\nEconomy Class Seats: Other than the above\n\n");
}

this is my full code for the program guys..please correct me if there are anything.... =) ur advise are urgently needed....

My advice was to not use a 4 dimensional array when one is not needed. In fact my claim is that using a 4d array in this case is not good programming. If you were to declare a 2d array with this data:

seats where MAX SEATS is 50
people where MAX PEOPLE is 10

You would then have array[10][50] which is 10 arrays of 50 elements each = 500 elements. But you only have 60 elements. It seems to me that the larger your MAX sizes are declared, the more space you are wasting, unless I am either that tired, or your algorithm is that strange. Additionally, using a 4D array is obviously making your program difficult to debug, so why don't you switch to a sensible alternative? If you don't believe me, then wait for the C experts to come in here, they'll be quick to point out (rightfully so) that I'm wrong if I am wrong.

Okie brother... but can i knoe wad is the alternative... bcoz here i have 2 flight...25 seats each flight and 5 seats are biz class while other 20 is economy class... Other than dat this flight will be travelling 5 times a day 7 days a week.... so what is ur idea brother.... =) check your inbox brother i have sent u a msg... =) thnkz

Please don't PM daniweb members. Personally I don't mind, but in general, that is the rule here. If people want to help they will respond in your thread. Regarding your PM, if your professor mentioned that it was extra credit to use more than a 2D array, then I must be mistaken about my entire post, so ignore all my posts in this thread. Thanks.

Please don't PM daniweb members. Personally I don't mind, but in general, that is the rule here. If people want to help they will respond in your thread. Regarding your PM, if your professor mentioned that it was extra credit to use more than a 2D array, then I must be mistaken about my entire post, so ignore all my posts in this thread. Thanks.

okie brother..im sorry... =) but i didnt mean that u r wrong..there are alternatives ways...i just thought of ur idea arrays of sturct...that will create records ryte...i think its a brilliant idea...maybe i will implement that after consulting from my professor...thnks brother...

no problem. If you want to go that route, I don't see how he could be upset. There are a lot of tutorials online on how to use structs.

no problem. If you want to go that route, I don't see how he could be upset. There are a lot of tutorials online on how to use structs.

alryte brother...thnk you..if i have any problem..i will get back to you yea... =)

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.