working code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int seat[2][4][5] = {0};
int a, b, c;
int selection1, selection2, selection3;
int choice;
int seatcount;
int fll;
int tix;
int yn;
void menu(void);
void menu2(void);
int menuselection1(void);
int menuselection2(void);
int menuselection3(void);
void printseats(void);
int printticket(void);
void anotick(void);
void iffullb1(void);
void iffulle1(void);
void iffullb2(void);
void iffulle2(void);
void klb(void);
void kle(void);
void lkb(void);
void lke(void);
void exit( int exit_code );
struct custinfo
{
char desg[4];
char fname[20];
char lname[20];
char icnum[20];
int seat;
}customer[2][4][5];
main()
{
menu();
}
void menu(void)
{
int selection1 = 0;
selection1 = menuselection1();
while (selection1>= 1 && selection1<= 3)
{
if (selection1 == 1)
{
menu2();
}
if (selection1 == 2)
{
printseats();
}
if (selection1 == 3)
{
puts("\nProgram aborted!\n");
exit(0);
}
}
}
void menu2(void)
{
int selection2 = 0;
selection2 = menuselection2();
while (selection2>= 1 && selection2<= 3)
{
if (selection2 == 1)
{
int selection3 = 0;
selection3 = menuselection3();
while (selection3>= 1 && selection3<= 3)
{
if (selection3 == 1)
{
klb();
}
if (selection3 == 2)
{
kle();
}
menu2();
}
}
if (selection2 == 2)
{
int selection3 = 0;
selection3 = menuselection3();
while (selection3 != 3)
{
if (selection3 == 1)
{
lkb();
}
if (selection3 == 2)
{
lke();
}
menu2();
}
}
menu();
}
}
int menuselection1(void)
{
int choice = 0;
do
{
puts("\n\n-----Solar Airways-----");
puts("\n");
puts("\n1. Reserve Ticket");
puts("\n2. Print Seats");
puts("\n3. Quit\n");
puts("\nEnter a selection: [1/2/3]");
scanf("%d", &choice);
}
while (choice < 1 || choice > 3);
return choice;
}
int menuselection2(void)
{
int choice = 0;
do
{
puts("\n\n-----Solar Airways-----");
puts("\nSelect Flight\n");
puts("\n1. KL to LK");
puts("\n2. LK to KL");
puts("\n3. Back\n");
puts("\nEnter a selection: [1/2/3]");
scanf("%d", &choice);
}
while (choice < 1 || choice > 3);
return choice;
}
int menuselection3(void)
{
int choice = 0;
do
{
puts("\n\n-----Solar Airways-----");
puts("\nSelect Class\n");
puts("\n1. Business");
puts("\n2. Economy");
puts("\n3. Back\n");
puts("\nEnter a selection: [1/2/3]");
scanf("%d", &choice);
}
while (choice < 1 || choice > 3);
return choice;
}
void printseats(void)
{
int yn = 0;
for (a=0; a<2; a++)
{
printf("\nFlight %d\n", a+1);
for (b=0; b<4; b++)
{
printf("\n");
for (c=0; c<5 ;c++)
{
printf("%d ", seat[a][b][c]);
}
}
}
printf("\nEnter 1 to CONTINUE");
scanf("%d", &yn);
if (yn = 1)
{
menu();
}
}
int printticket(void)
{
if (seat[a][b][c] == 0)
{
printf ("\nEnter Designation [Mr/Ms]: ");
scanf ("%s", &customer[a][b][c].desg);
printf ("\nEnter First name: ");
scanf ("%s", &customer[a][b][c].fname);
printf ("\nEnter Last name: ");
scanf ("%s", &customer[a][b][c].lname);
printf ("\nEnter IC number: ");
scanf ("%s", &customer[a][b][c].icnum);
seat[a][b][c] = 1;
seatcount = seatcount+1;
customer[a][b][c].seat = seatcount;
printf ("\nName: %s. %s %s", customer[a][b][c].desg, customer[a][b][c].fname, customer[a][b][c].lname);
printf ("\nIC Number: %s", customer[a][b][c].icnum);
printf ("\nSeat Number: %d", customer[a][b][c].seat);
}
return seatcount;
}
void anotick(void)
{
int tix=0;
do
{
printf("\nDo you want to reserve another ticket?[1.YES 2.NO]\n");
scanf("%d", &tix);
}
while (tix < 1 || tix > 2);
if (tix == 2)
{
menu();
}
}
void iffullb1(void)
{
int seatfull=0;
for (a=0; a<1; a++)
{
for (b=0; b<1; b++)
{
for (c=0; c<5; c++)
{
seatfull = seatfull + seat[a][b][c];
}
}
}
if (seatfull == 5)
{
printf ("\nAll seat are unavailable for this class.");
printf ("\nIs it acceptable to be placed in the economy class? [1.YES 2.NO]");
scanf("%d", &fll);
do
{
if (fll == 1)
{
kle();
}
if (fll == 2)
{
printf ("\nNext flight lauch in 3 hour.\n");
}
}while(fll < 1 || fll >2);
}
}
void iffulle1(void)
{
int seatfull=0;
for (a=0; a<1; a++)
{
for (b=1; b<4; b++)
{
for (c=0; c<5; c++)
{
seatfull = seatfull + seat[a][b][c];
}
}
}
if (seatfull == 15)
{
printf ("\nAll seat are unavailable for this class.");
printf ("\nIs it acceptable to be placed in the business class? [1.YES 2.NO]");
scanf ("%d", &fll);
do
{
if (fll == 1)
{
klb();
}
if (fll == 2)
{
printf ("\nNext flight lauch in 3 hour.\n");
}
}while(fll < 1 || fll >2);
}
}
void iffullb2(void)
{
int seatfull=0;
for (a=1; a<2; a++)
{
for (b=0; b<1; b++)
{
for (c=0; c<5; c++)
{
seatfull = seatfull + seat[a][b][c];
}
}
}
if (seatfull == 5)
{
printf ("\nAll seat are unavailable for this class.");
printf ("\nIs it acceptable to be placed in the economy class? [1.YES 2.NO]");
scanf("%d", &fll);
do
{
if (fll == 1)
{
lke();
}
if (fll == 2)
{
printf ("\nNext flight lauch in 3 hour.\n");
}
}while(fll < 1 || fll >2);
}
}
void iffulle2(void)
{
int seatfull=0;
for (a=1; a<2; a++)
{
for (b=1; b<4; b++)
{
for (c=0; c<5; c++)
{
seatfull = seatfull + seat[a][b][c];
}
}
}
if (seatfull == 15)
{
printf ("\nAll seat are unavailable for this class.");
printf ("\nIs it acceptable to be placed in the business class? [1.YES 2.NO]");
scanf ("%d", &fll);
do
{
if (fll == 1)
{
lkb();
}
if (fll == 2)
{
printf ("\nNext flight lauch in 3 hour.\n");
}
}
while(fll < 1, fll >2);
}
}
void klb(void)
{
int seatcount=0;
puts("\nBusiness Class [KL --> LK]\n");
for (a=0; a<1; a++)
{
for (b=0; b<1; b++)
{
for (c=0; c<5; c++)
{
iffullb1();
seatcount=0;
seatcount = printticket();
anotick();
}
}
}
}
void kle(void)
{
int seatcount=0;
puts("\nEconomy Class [KL --> LK]\n");
for (a = 0; a < 1; a++)
{
for (b = 1; b < 4; b++)
{
for (c = 0; c < 5; c++)
{
iffulle1();
seatcount=0;
seatcount = printticket();
anotick();
}
}
}
}
void lkb(void)
{
int seatcount=0;
puts("\nBusiness Class [LK --> KL]\n");
for (a=1; a<2; a++)
{
for (b=0; b<1; b++)
{
for (c=0; c<5; c++)
{
iffullb2();
seatcount=0;
seatcount = printticket();
anotick();
}
}
}
}
void lke(void)
{
int seatcount=0;
puts("\nEconomy Class [LK --> KL]\n");
for (a=1; a<2; a++)
{
for (b=1; b<4; b++)
{
for (c=0; c<5; c++)
{
iffulle2();
seatcount=0;
seatcount = printticket();
anotick();
}
}
}
}