#include<iostream.h>
const int len=10;
int len1=5,len2=50;
int FreeSeatNum(int* a,int b,int c);//空余作座位数
int FreeSeat(int* aa,int bb,int cc);//购票
void main()
{
int seat[len]={0};
int type;
while(1)
{
cout<<"Smoking seat left:"<<FreeSeatNum(&seat[0], 0, len1-1)<<endl;
cout<<"Nonsmoking seat left:"<<FreeSeatNum(&seat[len1], len1, len-1)<<endl;
cout<<"Please type 1 for 'smoking'"<<endl<<"Please type 2 for 'nonsmoking'"<<endl;
cin>>type;
if(type==1)//有烟区
{
int i,s;
i=FreeSeat( &seat[0], 0, len1-1);
if(i==-1)
{
{
cout<<"If you want the nonsmoking area ?"
<<"Y or N"
<<endl;
cin>>s;
i=FreeSeat( &seat[len1], len1, len-1);
}
if(((s=='y')||(s=='Y'))||(i!=-1))
cout<<"Your ticket number is:"<<i<<endl<<"It is in nonsmoking area."<<endl;
//b++;
if((s=='n')||(s=='N'))
cout<<"Next flight leave 6 hours."<<endl;
}
if(i!=-1)
cout<<"Your ticket number is:"<<i<<endl<<"It is in smoking area."<<endl;
}
else if(type==2)
{
int i,s;
i=FreeSeat( &seat[len1], len1, len-1);
if(i==-1)
{
{
cout<<"If you want the smoking area ?"
<<"Y or N"
<<endl;
cin>>s;
i=FreeSeat( &seat[0], 0,len1-1);
}
if(((s=='y')||(s=='Y'))||(i!=-1))
cout<<"Your ticket number is:"<<i<<endl<<"It is in smoking area."<<endl;
//b++;
if((s=='n')||(s=='N'))
if(i!=-1)
cout<<"Next flight leave 6 hours."<<endl;
}
cout<<"Your ticket number is:"<<i<<endl<<"It is in nonsmoking area."<<endl;
}
}
}
int FreeSeatNum(int*a,int b,int c)
{
int i,j=0;
for(i=0;i<c-b+1;i++)
if(a[i]==0)
j++;
return j;
}
int FreeSeat(int*aa,int bb,int cc)
{
int i;
for(i=0;i<cc-bb+1;i++)
if(aa[i]==0)
break;
if(i==cc-bb+1)
return -1;
else
{
aa[i]=1;
return i+bb;
}
}
高手帮忙看下,可以编译一下看看