#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int userInput();
int main()
{
clrscr();
int x,y;
const int row= 12,seat= 5;
char plane[row][seat];
cout<<"\t\tAirplane Seat Arrangement"<<endl;
cout<<"\tA\tB\tC\tD\tE\tF"<<endl;
{for (y=1;y<=13;y++)
{ cout<<"Row "<<y<<"\t";
{for(x=0;x<=5;x++)
{ plane[y][x]='*';
cout<<plane[y][x]<<"\t";
}
cout<<endl;
}
}
}
userInput();
cout<<"Congratulations!! You Now Have A Seat...."
<<" Happy Trip!!!";
getch();
return 0;
}
int userInput()
{int tt,tr,nsa;
int a,b;
const int row= 12,seat= 5;
char plane[row][seat];
char tc;
char A=1;
char B=2;
char C=3;
char D=4;
char E=5;
char F=6;
cout<<"\nEnter TICKET TYPE [1]First Class [2]Economy Class : ";
cin>>tt;
switch(tt)
{case 1:
{
{cout<<"Enter TICKET [1-2]ROW NUMBER : ";
cin>>tr;
{ if ((tr>=1)&&(tr<=2))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
cin>>tc;
if ((tc>='A')&&(tc<='F'))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl; }
}
{
for (a=0;a<=2;a++)
for (b=0;b<=5;b++)
plane[a][b] ='X'; }
cout<<plane[a][b];
}
break;
case 2:
{cout<<"[1]Non-Smoking Area [2]Smoking Area : ";
cin>>nsa;
switch(nsa)
{case 1:
{cout<<"Enter TICKET [3-7]ROW NUMBER : ";
cin>>tr;
{ if ((tr>=3)&&(tr<=7))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
cin>>tc;
if ((tc>='A')&&(tc<='F'))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
} }break;
case 2:
{cout<<"Enter TICKET [8-13]ROW NUMBER : ";
cin>>tr;
{ if ((tr>=8)&&(tr<=13))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
cout<<"Note : Letter is CASE SENSITIVE!!!"<<endl;
cout<<"Enter TICKET [A-F]COLUMN LETTER : ";
cin>>tc;
if ((tc>='A')&&(tc<='F'))
cout<<"Input Accepted..."<<endl<<endl;
else
cout<<"Invalid Input!!!"<<endl<<endl;
}break;
default:
cout<<"INVALID INPUT!!!"<<endl;break;
} }
}
default:
cout<<"INVALID INPUT!!!"<<endl;break;
}
return userInput();
}
You need to format and use code tags.
[code=cplusplus]
// paste code here
[/code]
Your code is very hard to read due to to the lack of indentation. You also have a whole bunch of extra brackets that do nothing. The compiler doesn't care about the extra brackets, but combined with the lack of indentation, it makes it hard to tell where code blocks begin and end.
You already have your array set up. When a person buys a seat, he/she will be assigned a row and a seat. '*' means the seat is empty, 'X' means it is taken. So when you reserve a seat at row myRowNum and seat mySeatNum, you'll do this:
plane[myRowNum][mySeatNum] = 'X';
Depending on how you want to organize your program, you'll need to change the userInput function so that it can somehow do something with that row and seat number once you get valid input. You'll either need to pass it your array or pass the row and seat numbers by reference so you can use them when the function returns to main(), or something similar.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Lot's of things.
My first tip, never write more than a few lines, and clearly never more than a single action, without compiling and testing. By doing that you would find that you are overwriting your array and getting junk. Be sure you can initialize all elements of the variable plane to valid default values and display the state of the plane before you do anything else.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Ditto what Lerner and joshmo said. See my earlier post regarding code tags, extra brackets, and formatting/indentation, as well as joshmo's links.
const int row= 12,seat= 5;
char plane[row][seat];
cout<<"\t\tAirplane Seat Assignment"<<endl;
cout<<"\tA\tB\tC\tD\tE\tF"<<endl;
{for (y=1;y<=13;y++)
{ cout<<"Row "<<y<<"\t";
{for(x=0;x<=5;x++)
{ plane[y][x]='*';
Line 8 - Plane is defined for row indexes 0 through 11 in line 3. C++ arrays start with index 0, not 1. y is allowed to equal 13 in this loop. x is allowed to be 5. So you are defining in line 8, at some point, this:
plane[13][5] = '*';
plane[][] is only defined through plane[11][4]. That may not cause you problems, but that would be dumb luck if it doesn't. You need to change your array indexing so it starts at 0, or allocate more space.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711