Hello! I was having trouble with this program i keep getting undeclared identifier errors for my seat array and my seatnumber variable. I was also wondering if i was going about writing this program the right way. Arrays are kinda new to me. This is the problem

(Airline Reservatins System) A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats).
Your program should display the following menu of alternatives - Please type 1 for "First Class" and Please type 2 for "Economy". If the person types 1, your program should assign a seat in the first class section (seats 1-5). If the person types 2, your program should assign a seat in the economy section (seats 6-10). Your program should print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane.
Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of the array to 1 to indicate that the seat is no longer available.
Your program should, of course, never assign a seat that has already been assigned. When the first class sections is full, your program should ask the person if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours."

# include <stdio.h>


int askflight(void);
int AddToEcomonyClass(int);
int addToFirstClass(int);
int seatingapp(void);

int main (void)
{
	seatingApp();


	return 0;


}
int seatingApp(void)
{
	int seat[40]={0};
	int seatnumber;
	
	askflight();
}

int askflight(void)
{
	int choice;
	

	printf("Please type 1 for first class\n please type 2 for economy.");
	scanf("%d", &choice);

	if (choice == 1)
		seatnumber = addToFirstClass(seat);
		if (seatnumber == -1)
			printf("The first class flight is full");
		if (choice =2)
			seatnumber = addToEconomyClass(seat);

			if (seatnumber ==-1)
				printf("The economy class flight is full!");


		
}
int addToFirstClass(int seat[40])
{
	int t;
	

	for(t=0;t<10;t++)
		if (seat[t] == 0)
			return t;
		else return -1;

}
int AddToEcomonyClass(int Seat[40])
{
	int t;
	
	for(t=10;t<40;t++)

		if(Seat[t] == 0)
			return t;
		else return -1;

}

Recommended Answers

All 5 Replies

I see you TRIED to use code tags. Good effort. I'm not sure why they didn't work. Here's your code with the undeclared identifier errors fixed. It probably doesn't work correctly (I didn't bother to check that) but at least it will run for you.

#include <stdio.h>

int askflight(int[]);
int addToEcomonyClass(int[]);
int addToFirstClass(int[]);
int seatingapp(void);

int main (void)
{
  seatingApp();
  return 0;
}

int seatingApp(void)
{
  int seat[40]={0};
  int seatnumber;
  askflight(seat);
}

int askflight(int seat[])
{
  int choice, seatnumber;
  printf("Please type 1 for first class\n please type 2 for economy.");
  scanf("%d", &choice);

  if (choice == 1)
    seatnumber = addToFirstClass(seat);
  if (seatnumber == -1)
    printf("The first class flight is full");
  if (choice =2)
    seatnumber = addToEconomyClass(seat);

  if (seatnumber ==-1)
    printf("The economy class flight is full!");
}

int addToFirstClass(int seat[])
{
  int t;
  for(t=0;t<10;t++)
    if (seat[t] == 0)
      return t;
  return -1;
}

int addToEconomyClass(int seat[])
{
  int t;
  for(t=10;t<40;t++)
    if(seat[t] == 0)
      return t;
  return -1;
}

capacity: 10 seats

int seat[40]={0};        /*What for?*/

You don't loop through your statements to see whether

both the choices work for you

if (choice =2)

If suppose I have booked a ticket,have you placed a 1 in the index position of

seat[40]; /*for 10 seats, shouldn't 10 be sufficient?
           assuming that 0-4 for first class
          5-9 for economy class*/
/*If choice=1 place a 1 in0-4 position 
    else if choice is 2 place a 1 in 5-9 position*/

Watch out for::

int addToEcomonyClass(int[]);
int seatingapp(void);

Sorry about the forty. I wasn't clear on my post. My teacher increased the max volume to forty , 10 for first class and 30 for economy.

Okay i changed my code around a little bit. i decided to start off easy and just get it to read in user choice and name and print them out, but i am getting the stupid undeclared identifier error for almost all the variables ive declared.

#include <stdio.h>
#define SIZE 40
#define FCLASS 10
#define ECOMNOMY 30
#define FIRST 20
#define LAST 20

int askFlight(void);
void askName(void);
//int assignSeat(int []);
void printBPass(char,char,int);
//int seatCheck(int []);

int main(void)
{
	int seatnumber;
	//int seat[SIZE];
	char choice2;

	do{
		seatnumber++;

	askFlight();
	askName();
	printBPass(firstname,lastname,seatnumber);






	puts("Would you like to board another flight?");
	scanf("%*c%c", &choice2);



	while (choice2 = 'y' || choice2 == 'Y')


  
  return 0;
}




void askFlight(void)
{
  int choice;
//  int i;
//  int seats

  printf("Please type 1 for first class\nplease type 2 for economy.");
  scanf("%d", &choice);

  /*if (choice = 1){
	  for (i=0,i<10,i++)
		  seats[i]=1;
  }
  else {
	  for(i=11;i<40;i++)
		  seats[i]=1;*/


}
void askName(void)
{
	char firstname[FIRST];
	char lastname[LAST];
	

	puts("Please enter your first name\n");
	scanf("%s", firstname);

	puts("Please enter your last name");
	scanf("%s", lastname);
}

/*int seatCheck(int seat[])
{
	int seatavail;
	

	
}
*/
/*
int assignSeat(int seatnumber[])
{
	int seatnumber[SIZE];

	for(i=0;i < SIZE;i++);
	if seatnumber[i]


}*/
void printBPass(char firstname[], char lastname[], int seatnumber)
{
	printf("%s%s%d",firstname,last,seatnumber);

}

First of all,you must pass your array

seat[40]

to your function

int askFlight(void);

.
Else how will the contents of the original array change?Also in the function definition and prototype,

void askFlight(void) /*definition*/
int askFlight(void) /*prototype*/

You must also fill all your array elements with 0 (you did it in the first post)
In

void askFlight(void)

Now

if( choice==1) /*Should be ==*/
int i; 
 int seat_booked=0;
if ( choice==1)
   {
     for( i=0 ; i<FCLASS ; i++)
         {
           if(seat[i]==0)
              {
               seat[i]=1;
               seat_booked=1;/*Seat secured*/ 
               askName(i);
               break;
                 
                                   /*Only 1seat/person You were assigning all   of  them to one person*/ 
               } 
        }
   if(seat_booked==0) /*Means the passenger hasn't got a seat*/
   /*Design a function which will look for seats in economy class
,obviously you must first ask whether assigning a seat in economy class is acceptable */
  /*If it still can't find a seat ,then all the seats are booked.l*/
}
 else
 {
     for( i=FCLASS ; i<SIZE ; i++)
         {
           if(seat[i]==0)
              {
               seat[i]=1;
               seat_booked=1; 
               askName(i);
               break;
                 
                                   /*Only 1seat/person You were assigning all   of  them to one person*/ 
               } 
        }
   if(seat_booked==0)
   /*Design a function whick looks for seats in first class,better still overload the earlier function */
}

In the

main()

, you must not

seatnumber++;/*As its not certain that every passenger will get a seat*/

And in the function

askName(int seat_number)/*I changed it*/
{
 char firstname[FIRST];
	char lastname[LAST];
	

	puts("Please enter your first name\n");
	scanf("%s", firstname);

	puts("Please enter your last name");
	scanf("%s", lastname);
                 
             printBPass(firstname, lastname,  seat_number);/*Call from inside this function itself*/

}

You will then certainly have to make changes in the main().

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.