K...so this is an airline reservation program I have been working on for school and I can't see where I am going wrong. Basic functions of this would be taking reservations for either first class or economy class seating on a 10 passanger plane. seats 1-5 are supposed to be 1st class and 6-10 are supposed to be economy.
----------------------------------------------------------------------
HERE'S MY CODE:

#include <stdio.h>
 #include <stdlib.h>
 //arline res system
 //10 char array to hold seats
 //choose 1 for first class
 //choose 2 for economy
 //seats 1-5 first class
 //seats 6-10 economy
 //show a ticket stub with res#
 //show which seats are available/taken
 //if first class is full then prompt 
 //for econ and vice versa
 
 int firstClass[5]={1,1,1,1,1};
  int econClass[5]={0,0,0,0,0};
 main()
 {
       //vars
       char choice;
       //prompt
       printf("welcome");
       printf("\n");
       printf("This begins the process of checking available seating");
       printf("\n");
       printf("Press 1 for First Class and 2 for Economy");
       printf("\n");
       scanf(" %c", &choice);
       
       if (choice=='1')
       {
          purchaseFC();
       }
       else if (choice=='2')
       {
          purchaseEcon();
       }//end else if
       else
       {
            printf("invalid choice"); 
            printf("\n"); 
            main(); 
       }  //end else 
 }//end main
 purchaseFC()
 {   printf("welcome to purchaseFC");

     int ctr;
     for (ctr=0; ctr<5; ctr++)
     { 
         if (firstClass[ctr] == 0)
         {
           printf("Seat: %d is available", firstClass[ctr]);
           ctr++;
           system("PAUSE");
         }
     
     else
     {
         char choice2;
         printf("No First Class Available");
         printf("\n!\n!\n");
         retry:    
         printf("Would you like an economy ticket");
         printf("\n 1-yes or 2-no \n");
         scanf(" %c", &choice2);
         
         if (choice2=='1')
         {
              purchaseEcon();
         }  
         else if  (choice2=='2')    
         {
              printf("Sorry we could not get you on this flight.");
              printf("\n Please shop Roscos Flights in the future\n");
              system("PAUSE");return 0;
         }   
         else
         {
            printf("invalid choice"); 
            printf("\n"); 
            goto retry;
         }  //end else 
         } 
     }//end else
}// end PurchaseFC
 purchaseEcon()
 {printf("welcome to purchaseEcon");
     int ctr;
     for (ctr=0; ctr<5; ctr++)
     {
     //only show subscripts = 0
     if (econClass[ctr] == 0)
     {
       printf("Seat: %d is available", econClass[ctr]);
     }
     
     else
     {
         char choice3;
         printf("No Econ Available");
         printf("\n!\n!\n");
         retry1:    
         printf("Would you like a First Class ticket");
         printf("\n 1-yes or 2-no \n");
         scanf("%c", &choice3);
         
         if (choice3=='1')
         {
              purchaseFC();
         }  
         else if  (choice3=='2')    
         {
              printf("Sorry we could not get you on this flight.");
              printf("\n Please shop Roscos Flights in the future\n");
              system("PAUSE");return 0;
         }   
         else
         {
            printf("invalid choice"); 
            printf("\n"); 
            goto retry1;
         }  //end else 
         }       
     }///end else
 }//end  purchaseEcon()

doesnt look like i wrapped the text in code tags :( sorry if thats the case

Eww, never use a goto statement, there is always an alternative to it and can be messy. As for the problem, do you mind giving us the error(s)? I could do it but i'm currently on a school computer.

Visibly I can't find any apparent errors but your code is quite messy.

well theres no error. lol....the problem is it keeps seating people in seat 0 and saying that seats 0 0 0 0 are available. it runs fine but my array is screwie i guess...

well theres no error. lol....the problem is it keeps seating people in seat 0 and saying that seats 0 0 0 0 are available. it runs fine but my array is screwie i guess...

Yes, there is an error. You're describing the error. So no, it doesn't run fine. It may compile and it may run to completion, so it "runs fine" according to the OS (if it compiles and runs to completion and returns 0, it's a "success" for the OS).

Regardless of the semantics of the code itself, take a look back and try to take a birds-eye view. What's the user supposed to experience when they run this program? How many times are they supposed to be asked certain questions? What should be displayed under what circumstances? Now look at your loop control and if-statements and see if those match the needs. I think the overall design is flawed, regardless of the code itself, so describe exactly what you want in English, then turn that English into C++.

well theres no error. lol....

Consider getting a 'second opinion' by e.g. downloading and installing Code::Blocks (~15 MBs), i.e. you might get it up and running in no time. Then you might post back with what the new compiler is telling you.

Yes, there is an error. You're describing the error. So no, it doesn't run fine. It may compile and it may run to completion, so it "runs fine" according to the OS (if it compiles and runs to completion and returns 0, it's a "success" for the OS).

Regardless of the semantics of the code itself, take a look back and try to take a birds-eye view. What's the user supposed to experience when they run this program? How many times are they supposed to be asked certain questions? What should be displayed under what circumstances? Now look at your loop control and if-statements and see if those match the needs. I think the overall design is flawed, regardless of the code itself, so describe exactly what you want in English, then turn that English into C++.

thanks...good advice. i really need to start with pseudo-code before jumping right into things. working out the array now. why is it not a good idea to use :goto:'s? by the way

thanks...good advice. i really need to start with pseudo-code before jumping right into things. working out the array now. why is it not a good idea to use :goto:'s? by the way

Maybe search the internet for the topic "spaghetti code". Generally, first learn how to program without the 'goto' and then later on figure out the good uses of it.

Once you've done the pseudo-code part and start writing the code again, you really should consider grabbing yourself a decent compiler, which would be barking at you, given the above code. In other words, your current compiler is 'sloppy enough' to let you in for surprises. ;)

commented: Lol spaghetti code! Didn't know about that one +1
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.