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()