关于自动寄存柜的问题求解
红字部分看不懂,求解答#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main(void)
{
int i,k,num,x,count,coin,temp;
int b[1000],a[1000],full[1000];
int password,flag=0;
srand((int)time(0));
printf("寄存柜数量:");
scanf("%d",&num);
printf("\n");
/*---------*/
count=0;
while(1){
printf("1.投硬币2.输密码0.退出请选择:");
scanf("%d",&x);
printf("\n");
/*-------*/
if(x==1){
printf("投币值:");
scanf("%d",&coin);
printf("\n");
if(coin==1){
if(count<num){
b[count]=rand()%num+1;
while(full[b[count]-1]==1){
b[count]=rand()%num+1;
for(i=0;i<count;i++){
if(b[count]==b[i]){
b[count]=rand()%num+1;
i=0;
}
}
}
full[b[count]-1]=1;
a[count]=rand()%9000+1000;
for(i=0;i<count;i++){
if(a[count]==a[i]){
a[count]=rand()%9000+1000;
i=0;
}
}
printf("寄存箱编号:%d 密码:%d\n\n",b[count],a[count]);
count++;
}
else
printf("本柜已满\n");
}
else{
printf("投错硬币, 请重新选择\n\n");
continue;
}
}
else if(x==2){
printf("输入密码:");
scanf("%d", &password);
printf("\n");
if(count==0){
printf("密码错误\n\n");
continue;
}
for(i=0;i<count;i++){
if(full[b[i]-1]==1&&password==a[i]){
printf("%d号寄存箱已打开\n\n",b[i]);
full[b[i]-1]=0;
flag=1;
for(k=i;k<count-1;k++){
b[k]=b[k+1];
a[k]=a[k+1];
full[b[k]-1]=full[b[k+1]-1];
}
break;
}
}
if(flag!=1)
printf("密码错误\n\n");
else{
count--;
flag=0;
}
}
else if(x==0)
break;
else
printf("输入错误, 请重新输入\n\n");
}
return 0;
}