ok my teacher wants me to write a program using these instructions :

A small airline has just purshased a computer for its new automated reserations 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 alternatives--Please type 1 for "First Class" and PLease type 2 for "Economy". If the persons types 1, YOur program should assign a seat in the first class section (seat 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 one-dimensional 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 section is full, Your program should ask the person if it is acceptable to be placed in the economy section(and viceversa). If yes, then make the appropiate seat assignment. If no, the print the message "Next flight leaes in 3 hours".

this is what i have so far and i need to know what can i do assign each section a seat, but individually, i don't want it to print all together, i just want to ask do yo want first class or economy depending on the answer i assign the corresponding seat can someone help me pleaseee what is im doing wrong


//Airplane Reservation System

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <iomanip>
using std::setw;


int main()
{
int firstClass = 0;//first class section
int economy = 0;//economy section
int sections= 0;//to choose the section of the seats
int total = 0;
int sectionsCounter = 0;
//use an array for the capacity of 10 seats
int seats[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

//Menu Alternatives

cout<<"Please type 1 for ""First Class"":"<<"\n"<<endl;
cout<<"Please type 2 for ""Economy"":"<<endl;
cin>>sections;

//use an if statement to assign a seat in first class
if ( sections == 1)
{
sections = 1;
cout<<"First Class"<<setw (13)<<"Seats"<<endl;

for ( int i = 0; i <= 4; i++)

cout<<setw(7)<<sections<<setw (13)<<seats<<endl;
}//end of if

//use a if statement to assign a seat in economy section
else
if ( sections == 2)
{
sections = 1;
cout<<"Economy"<<setw (13)<<"Seats"<<endl;
for ( int i = 5; i < 10; i++)

cout<<setw(7)<<sections<<setw (13)<<seats<<endl;
}//end of if
system("pause");
return 0;
}//end of main

You mean something like this:

if ( sections == 1) //first class reqeusted
{ 
   if(firstClass < 4)//implies there's only 4 first class seats available on this flight
      ++firstClass; //assign a seat in first class
}

no, what i mean is that the program should print First Class or Economy 0 until the user inputs the number of section, and when the user choose wich section they want, the program should assign a seat for each section, if it is first class it has to be in the seats from 1-5 and if it is economy it has to be in the seats from 6-10

If you want it to print out 0's then set the array to 0's

int seats[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

with this you're setting each array with it's respective number.

also as a heads up if you're looking for this to loop until all the seats are full you need to set a lop before the menu starts to go back to the menu once the user is done making his selections.

//use an if statement to assign a seat in first class
if ( sections == 1)
{
sections = 1;
cout<<"First Class"<<setw (13)<<"Seats"<<endl;

for ( int i = 0; i <= 4; i++)

cout<<setw(7)<<sections<<setw (13)<<seats[i]<<endl;
}//end of if

with this you're only printing out the numbers between seats[0] to seats[4]. first thing first take out the sections = 1; its doing nothing. Then find a way to change seats[] to the value 1 once they selected either 1 or 2 for their seating. I would do something like
int i =0;
while (i < 4 && seats ==1)
i++;
seats = 1;

Hope this helps out.

Use firstClass and and economy to calculate indexes into the array of seats which represent the first available seat in each section. Here's something that might guide you.

if(sections == 1) //customer wants first class
{
   if(firstClass < 5)/*there's only 5 seats in first class, they are seats[0], seats[1], seats[2], seats[3], and seats[4]*/
      cout << "you will be assigned seat  " << seats[firstClass];
      /*now there's one less seat class in first class
so increment firstClass so you don't give the seat out twice*/
      ++firstClass;  
}
if(sections == 2)  //they want economy.
  /*the first open seat in economy will be at index i == 5 + economy.  You can write the code notifying the customer what seat they were assigned and keeping track of the next available seat in economy */

Thanks for all your help it was very helpful

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.