Booking seats program question..
Hi! I made a program in order to book an airplane's seats. Here is my code:
Code:
#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
void message(void);
int main()
{
const int limit=10;
int c,i,a[limit];
int num;
static int seat1=0;
static int seat2=0;
static int sum1,sum2;
while(seat1<5&&seat2<10)
{
message();
cin>>num;
for(i=0;i<5;i++)
a[i]=0;
if(num==1)
{
a[i]=1;
seat1+=a[i];
sum1=seat1;
cout<<" You bought seat "<<seat1<<" in first class"<<endl;
}
if(seat1==5) // Here is the problem!
{
cout<<"First class is full.."<<endl;
cout<<"Do you want a seat in economical class?..<<endl;
cin>>num;
}
for(c=5;c<limit;c++)
a[i]=0;
if(num==2)
{
a[i]=1;
seat2+=a[i];
sum2=seat2;
cout<<"You bought seat "<<seat2<<" in eco class"<<endl;
}
continue;
if(num==0)
{
cout<<"Exiting.."<<endl;
cout<<"The seats in first class are: "<<sum1<<endl;
cout<<"The seats in economical class are: "<<sum2<<endl;
system("pause");
return 0;
}
continue;
}
system("pause");
return 0;
}
void message(void)
{
cout<<"Choose an option: 1 for first class, 2 for economical class or 0 to quit"<<endl;
}
Here is the problem!
my question is that when the seats1 reaches 5 the program asks if the user want a seat in economical class..then i put "cin>>num", the program books 1 seat in economical class but then exits..can i do something to book 1 seat in eco class and then continue with the remaining seats...?