| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 781 人关注过本帖
标题:关于自动寄存柜的问题求解
只看楼主 加入收藏
在93的孩子
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-6-5
收藏
 问题点数:0 回复次数:0 
关于自动寄存柜的问题求解
红字部分看不懂,求解答
#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;  
}  
搜索更多相关主题的帖子: 密码 count 寄存柜 include password 
2013-06-05 23:01
快速回复:关于自动寄存柜的问题求解
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024180 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved