good day!

we were given a project. it is a program for an airline company.
in this program, the user can view vacant seats in the airplane then
he can make a reservation in any of those seats or cancel a reservation
he had made. he can also view the reserved seats if he wants.
what are the correct codes for this?

i have already made a program but the problem is, it will not show the reserved seats.

thank you so much for helping me...:)

Then post your code so we can help you.
Don't forget to use the CODE tags when you post it.

ok.. perhaps i'll give it next week.. it's quiet long and i can't type it all here... it's saved on our school's pc...

copy and paste it :)

good day!!!
here is my code: (sorry for it really ain't good)

#include<stdio.h>
struct list{
  int stn[10];
}var;
char choice,ans;
int x=1, st2;

main()
{
  clrscr();
 printf("[1] View Vacant Seats\n");
 printf("[2] REserve a Seat\n");
 printf("[3] CAncel a Reservation\n");
 printf("[4] Exit\n");
 printf("enter choice: ");
 choice=getch();
 switch(choice)
{
  case '1': view();
  case '2': reserve();
  case '3': cancel();
  case '4': clrscr();
               printf("Thanks! Come Again!");
               getch();
               exit(0);
  default: printf("Invalid Input!");
              getch();
              main();
 }
}

view()
{
 clrscr();
 if(x>10){
 printf("All Seats are occupied!");
 main();
}
 else{
 for(x=1;x<=10;x++){
  printf("enter seat no. : ");
 scanf("%d",&var.stn[x]);
 printf("\nReserve Another? (y/n)");
 ans=getch();
 if(ans=='y' || ans=='Y'){
 reserve();
}
else{
 main();
}
}
}
}

cancel()
{
 clrscr();
 if(x==0){
 printf("No reservation to cancel");
main();
}
else{
printf("Enter Seat No. : ");
scanf("%d",&stn2);
if(stn2==var.stn[x]){
 x--;
}
else{
printf("seat no. is not reserved!");
}
}
}

thank you so much for your kindness...
it really almost break my head!...
thanks a lot!!!!!:-D

dont use clrscr(); its a bad command

you need to add break statements at the end of each case statement so that the program does not execute the lines for the next case statements.

delete line 60 -- never ever for any reason call main() from anywhere within your program. That function is intended to be called only from the program's startup code.

>> it will not show the reserved seats
I would create an array of ints that represent each seat in the plain and the status of that seat, such as unassigned, assigned, reserved, etc. That makes it easy to know which seats have been reserved.

thank you so much for the advices...
uhmm.. how can i make the viewing of reserve seats work?
i still cant get it...:-(

If you have an int array of all seats, initialize the elements with 0. When someone reserves a seat change it to 1. When someone shows up and claims the seat change it to 2.

Then to show all the reserved seats iterate through the array and print the ones whose value is 1. For example

for(int i = 0; i < MaxSeats; i++)
{
     if (seats[i] == 1 )  // a reserved seat
          printf("Seat %d is reserved.\n", i);
}

thank you so much.......:)
i hope i can make it right this time...:S

hello...
i really need the code for airplane seat reservation..
can you pass it to me.
thank you..

Ah, that time in the semester again.

NO.

Search like the rest of us and cheat the hard way.

commented: YES +4
#include<stdio.h>
      struct list{
      int stn[10];
      }var;
      char choice,ans;
      int x=1, st2;
       
      main()
      {
      clrscr();
      printf("[1] View Vacant Seats\n");
      printf("[2] REserve a Seat\n");
      printf("[3] CAncel a Reservation\n");
      printf("[4] Exit\n");
      printf("enter choice: ");
      choice=getch();
      switch(choice)
      {
      case '1': view();
      case '2': reserve();
      case '3': cancel();
      case '4': clrscr();
      printf("Thanks! Come Again!");
      getch();
      exit(0);
      default: printf("Invalid Input!");
      getch();
      main();
      }
      }
       
      view()
      {
      clrscr();
      if(x>10){
      printf("All Seats are occupied!");
      main();
      }
      else{
      for(x=1;x<=10;x++){
      printf("enter seat no. : ");
      scanf("%d",&var.stn[x]);
      printf("\nReserve Another? (y/n)");
      ans=getch();
      if(ans=='y' || ans=='Y'){
      reserve();
      }
      else{
      main();
      }
      }
      }
      }
       
      cancel()
      {
      clrscr();
      if(x==0){
      printf("No reservation to cancel");
      main();
      }
      else{
      printf("Enter Seat No. : ");
      scanf("%d",&stn2);
      if(stn2==var.stn[x]){
      x--;
      }
      else{
      printf("seat no. is not reserved!");
      }
      }
      }

This is what I have come up with so far but I need A seat Reservation system for a 10 seater plane with seat 1-5 Firstclass and 6-10 Economy class.Displaying options to Choose btn the two classes and 3rd option to exit.
Then it has to av an array to represent the seating chart. With 0 as the initial indication that all seats are empty. Then when one section is full, request the permission to assign to the other section. If the request is declined, print out "Nextfligt leaves in 4 hours" Please help...

Use a stack.


This is what I have come up with so far ..[blabla]

This is what YOU came up with?? Don't make me laugh, it is the EXACT same code as the OP posted in this thread (30 days ago). If you're going to try to fool us, you really should try harder.

If you want advice about this code: Steal something better or perhaps try to write something YOURSELF, or is that too much to ask?

Niek

Excuse me my friend..I know that ... thats my pal and I helped to get that simple Seat reservation code...(smiles)..I aint that dumb for ur info! Im jus a cool guy who asked for help...thats all..Ok? If cant help just relax. Thankyou nway, I know guyz do that...bt some...not all...and I aint in that crew...!!chao

commented: "leet speek" is against the rules -4

dont use "leet speek"

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.