3 Replies - 3747 Views - Last Post: 25 January 2013 - 03:49 PM Rate Topic: -----

#1 pdroot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-January 13

help with airline reservation in c

Posted 25 January 2013 - 02:52 AM

I need help with this code I've been working on all night long. this is what the assignment says:

Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with 6 seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class. You program will prompt the user to enter their ticket type, and then their userid (this will just be an arbitrary number picked by you).
This will be implemented by using a two-dimensional array. Every element in the array will be initialized to zero. You will be able to tell if a seat is open if it has a value of 0.
The program will then fill the seats from smallest to largest in the appropriate row per the ticket type. It will print to the user which seat they were given, or if all seats for that ticket type were full, it will print a message indicating all seats for that ticket type are full. If there is an open seat, the user’s userid will be placed in the array indicating that seat is taken.
Once they are done reserving seats (they enter “N” when asked if they’d like to reserve another seat), the contents of the array will be printed to show that the seats were in fact reserved as entered. An example of how the program should look is given on the next page.

what i can't seem to figure out is this part Once they are done reserving seats (they enter “N” when asked if they’d like to reserve another seat), the contents of the array will be printed to show that the seats were in fact reserved as entered. An example of how the program should look is given on the next page.

this is what i have so far.
#include <stdio.h>

int printMenu();



int main()
{
	printf("welcome to the airline reservation system\n");
	int airlineSeats[13][6]={0};
	int colSize=13;
	int rowSize=6;
	int ticketNumber;
	int reRun;
	int r,c;



		int menuChoice=printMenu();

		switch(menuChoice)
			{


			case 1:


			for(r=0; r<=1; ++r)    //This loops on the rows.
				{

					for(c=0; c<6; c++) //This loops on the columns
					{

					printf("Please enter your ticket number\n");
					scanf("%i", &airlineSeats[r][c]);
					printf("You have been assigned to row %i seat %i\n",r+1,c+1);
					printf("Would you like to reserve another seat? type 1 for yes 2 for no\n");
					scanf(" %i", &reRun);


				}
				}
break;



case 2:

					for(r=2; r<=6; ++r)    //This loops on the rows.
						{
							for(c=0; c<6; c++) //This loops on the columns
							{

							printf("Please enter your ticket number\n");
							scanf("%i", &airlineSeats[r][c]);
							printf("You have been assigned to row %i seat %i\n",r+1,c+1);
							printf("Would you like to reserve another seat? type 1 for yes 2 for no\n");
							scanf(" %i", &reRun);
						}
						}

break;

case 3:

					for(r=7; r<=12; ++r)    //This loops on the rows.
						{
							for(c=0; c<6; c++) //This loops on the columns
							{

							printf("Please enter your ticket number\n");
							scanf("%i", &airlineSeats[r][c]);
							printf("You have been assigned to row %i seat %i\n",r+1,c+1);
							printf("Would you like to reserve another seat? type 1 for yes 2 for no\n");
							scanf(" %i", &reRun);
						}
						}


break;
	}



	for(r=0; r<rowSize; ++r)    //This loops on the rows.
		{
		for(c=0; c<colSize; c++) //This loops on the columns
			{
				printf("%i\t", airlineSeats[r][c]);
			}

		}

}

int printMenu()
{
printf("Please enter your ticket type\n");
printf("1. First Class\n");
printf("2. Business Class\n");
printf("3. Economy Class\n");

int menuChoice;
scanf("%i", &menuChoice);
return menuChoice;
}




This post has been edited by jimblumberg: 25 January 2013 - 07:11 AM
Reason for edit:: Fixed Code Tags.


Is This A Good Question/Topic? 0
  • +

Replies To: help with airline reservation in c

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,861
  • Joined: 02-June 10

Re: help with airline reservation in c

Posted 25 January 2013 - 06:46 AM

Quote

what i can't seem to figure out is this part Once they are done reserving seats (they enter “N” when asked if they’d like to reserve another seat), the contents of the array will be printed to show that the seats were in fact reserved as entered.


Don't over think it. Just loop through the array and print the seat number and the name of the reservation holder.

You seem to already have this

Quote

for(r=0; r<rowSize; ++r) //This loops on the rows.
{
   for(c=0; c<colSize; c++) //This loops on the columns
      {
        printf("%i\t", airlineSeats[r][c]);
      }

}

So when you say you can't figure it out - What is the real problem because it looks like you have?
Was This Post Helpful? 0
  • +
  • -

#3 pdroot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-January 13

Re: help with airline reservation in c

Posted 25 January 2013 - 07:26 AM

View PosttlhIn`toq, on 25 January 2013 - 06:46 AM, said:

Quote

what i can't seem to figure out is this part Once they are done reserving seats (they enter “N” when asked if they’d like to reserve another seat), the contents of the array will be printed to show that the seats were in fact reserved as entered.


Don't over think it. Just loop through the array and print the seat number and the name of the reservation holder.

You seem to already have this

Quote

for(r=0; r<rowSize; ++r) //This loops on the rows.
{
   for(c=0; c<colSize; c++) //This loops on the columns
      {
        printf("%i\t", airlineSeats[r][c]);
      }

}

So when you say you can't figure it out - What is the real problem because it looks like you have?


I guess what I'm really saying I I know what I'm doing I'm just having trouble organizing I know all the code I need is there I just couldn't get it to end the nested loop and print the array right.
Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1353
  • View blog
  • Posts: 4,660
  • Joined: 19-February 09

Re: help with airline reservation in c

Posted 25 January 2013 - 03:49 PM

You can check reRun in the for loop condition :

#define YESRERUN 2

for(r=0; r<=1 && reRun==2; ++r)  
{
  for(c=0; c<6 && reRun==YESRERUN; c++) 
  {
    /* ... */
  }
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1