#include
int main()
{
int num[2][6]={{0,0,0,0,0,0},{0,0,0,0,0,0}};
int i=0,j=0,m,n,p,z;
printf("Please type 1 for first class,Please type 2 for economy\n");
{
for(p=1;p<=10;p++)
{
scanf("%d",&z);
if(z==1&&num[0][4]!=1)
num[0][i]=1,
i++,
printf("头等舱%d,%d\n",1,i);
else if(z==2&&num[1][4]!=1)
num[1][j]=1,
j++,
printf("经济舱%d,%d\n",2,j);
else if(z==1&&num[0][4]==1)
{
printf("Can you change to the economy?\n");
scanf("%d",&m);
{
if(m==8)
{
num[1][p-5]=1,
j++,
printf("经济舱%d,%d\n",2,p-5);
}
else
printf("The next flight start in 3 hours later\n"),p=p-1;
}
}
else if(z==2&&num[1][4]==1)
{
printf("Can you change to the first class\n");
scanf("%d",&n);
{
if(n==9)
{
num[0][p-5]=1,
i++,
printf("头等舱%d,%d\n",1,p-5);
}
else
printf("The next flight start in 3 hours later\n"),p=p-1;}
}
else
printf("Error\n"),p=p-1;
}
}
printf("All tickets are sold!\n");
return 0;
}
就是这样一个程序,目的是选票,当输入1的时候自动给出头等舱以及位置序号,当输入2的时候给出经济舱以及位置序号。当然已被选择的不能再次被选择。
问题:
加入头等舱满了,会再次有一个if函数出来询问你是否可以换到经济舱,然而我定义
if(m=='y')
这个语句的时候会直接输出下面的else.....所以我不得不用数字来表示是否,比如输入8就代表可以,具体长这样
然而当我想用y来表示的时候,就变成这样了(运行时我已经把变量改成char 型,,输入时也是%c了)
请教如何解决?