看下哪里出错了
模拟售票系统(在Turbo 2.01中测试的)。 程序开始会提示输入 1 还是 2 ,1代表座位(1--5), 2代表座位(6--10)。程序红色部分会连续输出两次,不知道为什么; 还有输入1的次数等于6了,再输入2只能输入3次,按原来的想法应该还能输入4次的,调试了很久也没能让程序按想法运行, 请高手指点一下, 谢谢!!#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int roll1 (void);
int roll2 (void);
main()
{
int x[11]={0};
int b, c, d=0, e=0;
char h;
printf("Please type 1 for \"smoking\"\n");
printf("Please type 2 for \"nosmoking\"\n");
scanf("%d", &c);
srand(time(NULL));
while(d<5 || e<5)
{
if(c==1) /*c=1 在1到5中随机挑选一个数*/
{
d++;
if(d<=5)
{
b=roll1();
while(x[b]!=0) /*x[b]!=0 说明票已售出*/
b=roll1();
if(x[b]==0)
{
++x[b];
printf("The set at \"somking\", the number is %d\n", b);
printf("Please type 1 for \"smoking\"\n");
printf("Please type 2 for \"nosmoking\"\n");
scanf("%d", &c);
}
}
if(d>5)
{
e++;
if(e<5)
{
printf("Do you want to have a set for \"nosmoking\" (y or n): ");
scanf("%c", &h);
if(h=='y')
{
b=roll2();
while(x[b]!=0)
b=roll2();
if(x[b]==0)
{
++x[b];
printf("The set at \"nosmoking\", the number is %d\n", b);
printf("Please type 1 for \"smoking\"\n");
printf("Please type 2 for \"nosmoking\"\n");
scanf("%d", &c);
}
}
if(h=='n')
{
printf("Next flight leaves in 3 hours.\n");
printf("\nPlease type 1 for \"smoking\"\n");
printf("Please type 2 for \"nosmoking\"\n");
scanf("%d", &c);
}
}
}
}
if(c==2) /*c=2 在6到10中随机挑选一个数*/
{
e++;
if(e<=5)
{
b=roll2();
while(x[b]!=0)
b=roll2();
if(x[b]==0)
{
++x[b];
printf("The set at \"nosmoking\", the number is %d\n", b);
printf("Please type 1 for \"smoking\"\n");
printf("Please type 2 for \"nosmoking\"\n");
scanf("%d", &c);
}
}
if(e>5)
{
d++;
if(d<5)
{
printf("Do you want to have a set for \"somking\" (y or n): ");
scanf("%c", &h);
if(h=='y')
{
b=roll1();
while(x[b]!=0)
b=roll1();
if(x[b]==0)
{
++x[b];
printf("The set at \"smoking\", the number is %d\n", b);
printf("Please type 1 for \"smoking\"\n");
printf("Please type 2 for \"nosmoking\"\n");
scanf("%d", &c);
}
}
if(h=='n')
{
printf("Next flight leaves in 3 hours.\n");
printf("Please type 1 for \"smoking\"\n");
printf("Please type 2 for \"nosmoking\"\n");
scanf("%d", &c);
}
}
}
}
}
if(d>=5 && e>=5)
printf("Sorry, the flight is full! Next flight leaves in 3 hours.\n");
system("pause");
}
int roll1 (void)
{
int roll;
roll=1+rand()%5;
return roll;
}
int roll2 (void)
{
int roll;
roll=6+rand()%5;
return roll;
}