Thread: Two Mysteries or Problems

  1. #16
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    can u paste ur whole of the code

  2. #17
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    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();
                }
            }
        }
    }

  3. #18
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    Thanks but do you mind telling me where you've made changes?

  4. #19
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    And erm, it only allows buying one ticket. After that, they keep asking if I want another ticket. But they never ask for the personal details anymore.

  5. #20
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Just a question Zenghoong.

    Why a 3D array for the seats?

  6. #21
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    The first is for the flight, second for row, third for column

  7. #22
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    do u have any diff utility like vimdiff or beyond compare or emacs : diff please use it man u will able to understand where i made changes u want me to tell u everything please learn these tools also compare tools

  8. #23
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    Thats fine but one more problem. it only allows buying one ticket. After that, they keep asking if I want another ticket. But they never ask for the personal details anymore.

  9. #24
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    check the logic dude i haven't gone though the logic of the code. I just make ur code in a position where it can build successfully

  10. #25
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    do you mind going to my other thread. Need help with that question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM