Thread: Two Mysteries or Problems

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    24

    Two Mysteries or Problems

    I'm creating an airline reservation for my assignment and the menu is working fine. The two problems I'm currently facing are:

    1. After you choose LK and choose Business, the program displays the FULL message even before any tickets are booked. If you try with "KL Business", "KL"Economy" and "LK Economy", it will start asking for your designation. I've looked through the codes and are quite sure they are similar. Please help me find what is wrong.

    2. When you choose either "KL Business", "KL"Economy" and "LK Economy", they will ask you for your designation. But once I entered a value, errors keep popping out! Help.

    Here's my code:

    *code removed*
    Last edited by zenghoong; 10-13-2009 at 06:06 AM. Reason: removing codes

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    one error which is easily everyone can get is tyou are having two global variables with same name
    customer

    Code:
    int customer[2][4][5] = {0};
    And

    Code:
    struct custinfo
    {
    	char desg;
    	char fname;
    	char lname;
    	char icnum;
    	int  seat;
    }customer[2][4][5];

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    ur code was compiling on ur machine ??

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    It was. except it will display an error when it reaches the purchasing page.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    And, i tried removing this line

    Code:
    int customer[2][4][5] = {0};
    but nothing seems to have changed

  6. #6
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    what the hell u are coding man its big mistake dude

    see what the hell u r doin

    ur structure is

    Code:
    struct custinfo
    {
      char desg;
      char fname;
      char lname;
      char icnum;
      int  seat;
    }customers[2][4][5];

    and while inserting the data u r putting string

    man char is a single character it can hold like 'a' 'b' etc

    char* or char[] is a string of character like "rocky marrone" etc


    Code:
    int printticket(void)
    {
      if (seat[a][b][c] == 0)
        {
          printf ("\nEnter Designation [Mr/Ms]: ");
          scanf ("%s", &customers[a][b][c].desg);
          printf ("\nEnter First name: ");
          scanf ("%s", &customers[a][b][c].fname);
          printf ("\nEnter Last name: ");
          scanf ("%s", &customers[a][b][c].lname);
          printf ("\nEnter IC number: ");
          scanf ("%s", &customers[a][b][c].icnum);
    
          seat[a][b][c] = 1;
          seatcount = seatcount+1;
    
          customers[a][b][c].seat = seatcount;
    
          printf ("\nName: %s. %s %s", customers[a][b][c].desg, customers[a][b][c].fname, customers[a][b][c].lname);
          printf ("\nIC Number: %s", customers[a][b][c].icnum);
          printf ("\nSeat Number: %s", customers[a][b][c].seat);
    
        }
      return seatcount;
    }

    change ur structure like

    Code:
    struct custinfo
    {
      char* desg;
      char* fname;
      char* lname;
      char* icnum;
      int  seat;
    }customers[2][4][5];

  7. #7
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    do you suggest I use short instead of char?

  8. #8
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    And one more silly mistake

    Code:
    int printticket(void)
    {
      if (seat[a][b][c] == 0)
        {
          printf ("\nEnter Designation [Mr/Ms]: ");
          scanf ("%s", &customers[a][b][c].desg);
          printf ("\nEnter First name: ");
          scanf ("%s", &customers[a][b][c].fname);
          printf ("\nEnter Last name: ");
          scanf ("%s", &customers[a][b][c].lname);
          printf ("\nEnter IC number: ");
          scanf ("%s", &customers[a][b][c].icnum);
    
          seat[a][b][c] = 1;
          seatcount = seatcount+1;
    
          customers[a][b][c].seat = seatcount;
    
          printf ("\nName: %s. %s %s", customers[a][b][c].desg, customers[a][b][c].fname, customers[a][b][c].lname);
          printf ("\nIC Number: %s", customers[a][b][c].icnum);
          printf ("\nSeat Number: %s", customers[a][b][c].seat);
    
        }
      return seatcount;
    }
    In the above function customers[a][b][c].seat is of type int and you are using %s for it i think you should use %d otherwise it will give seg fault

    Code:
    int printticket(void)
    {
      if (seat[a][b][c] == 0)
        {
          printf ("\nEnter Designation [Mr/Ms]: ");
          scanf ("%s", &customers[a][b][c].desg);
          printf ("\nEnter First name: ");
          scanf ("%s", &customers[a][b][c].fname);
          printf ("\nEnter Last name: ");
          scanf ("%s", &customers[a][b][c].lname);
          printf ("\nEnter IC number: ");
          scanf ("%s", &customers[a][b][c].icnum);
    
          seat[a][b][c] = 1;
          seatcount = seatcount+1;
    
          customers[a][b][c].seat = seatcount;
    
          printf ("\nName: %s. %s %s", customers[a][b][c].desg, customers[a][b][c].fname, customers[a][b][c].lname);
          printf ("\nIC Number: %s", customers[a][b][c].icnum);
          printf ("\nSeat Number: %d", customers[a][b][c].seat);
    
        }
      return seatcount;
    }

  9. #9
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    After adding the * to the structure like this:

    Code:
    struct custinfo
    {
      char* desg;
      char* fname;
      char* lname;
      char* icnum;
      int  seat;
    }customers[2][4][5];
    The program won't run. It says

    Code:
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(227) : error C2224: left of '.fname' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(229) : error C2224: left of '.lname' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(231) : error C2224: left of '.icnum' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(236) : error C2224: left of '.seat' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(238) : error C2224: left of '.desg' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(238) : error C2224: left of '.fname' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(238) : error C2224: left of '.lname' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(239) : error C2224: left of '.icnum' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(240) : error C2224: left of '.seat' must have struct/union type

  10. #10
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    Its funny because after I added the * to everything, like this:

    *code removed*

    It says

    Code:
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(225) : error C2059: syntax error : '*'
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(227) : error C2059: syntax error : '*'
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(229) : error C2059: syntax error : '*'
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(231) : error C2059: syntax error : '*'
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(236) : error C2059: syntax error : '*'
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(238) : error C2059: syntax error : '*'
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(239) : error C2059: syntax error : '*'
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(240) : error C2059: syntax error : '*'
    Last edited by zenghoong; 10-13-2009 at 06:07 AM. Reason: remove code

  11. #11
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by zenghoong View Post
    And, i tried removing this line

    Code:
    int customer[2][4][5] = {0};
    but nothing seems to have changed
    Try removing a lot more than that. Any functions or other parts that aren't necessary to demonstrate the problem(s) should be removed before posting the code. By posting too much code you put most people off from bothering to try and help.
    You also lose some opportunity to possibly solve the problem on your own and gain the valueable experience from doing so.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  12. #12
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    k just do one thing then

    change ur structure like this it will work

    Code:
    struct custinfo
    {
      char desg[4];
      char fname[20];
      char lname[20];
      char icnum[20];
      int  seat;
    }customers[2][4][5];

  13. #13
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    Done. But now, it says:

    Code:
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(226) : error C2224: left of '.desg' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(228) : error C2224: left of '.fname' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(230) : error C2224: left of '.lname' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(232) : error C2224: left of '.icnum' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(237) : error C2224: left of '.seat' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(239) : error C2224: left of '.desg' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(239) : error C2224: left of '.fname' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(239) : error C2224: left of '.lname' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(240) : error C2224: left of '.icnum' must have struct/union type
    1>c:\users\user\desktop\pspd\ppspd6\ppspd6\pspd66.c(241) : error C2224: left of '.seat' must have struct/union type
    Don't know why it isn't working.

  14. #14
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    look at the structure more closley i m having name

    Code:
    struct custinfo
    {
      char desg[4];
      char fname[20];
      char lname[20];
      char icnum[20];
      int  seat;
    }customers[2][4][5];

    customers i think u must be using only customer

  15. #15
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    i've changed it all to customer now. But still no luck.

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