标题:为什么只能储存一个信息
只看楼主
moyurongxu
Rank: 1
来 自:广西科技大学鹿山学
等 级:新手上路
帖 子:35
专家分:6
注 册:2012-10-11
结帖率:62.5%
已结贴  问题点数:18 回复次数:2 
为什么只能储存一个信息
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define SIZE 10
    struct hotel
    {
        int jiage;/*价格*/
        int id;/*房间号码*/
        int kk;/*用来检测是否有人居住*/
    }room[]={{100,101,0},{100,102,0},{100,103,0},{100,104,0},{100,105,0},{100,201,0},{100,202,0},{100,203,0},{100,204,0},{100,205,0}};
    struct people
    {
        char name[10];
        char ID[20];
        char sex[2];
        int time;/*入住的时间*/
    }ke[SIZE];
    int n=0;
    void main()
    {
        void Insert();
        void Search();
        void Show();
        void save();
        void load();
        void jie();
        int i;
        load();
        do{
        printf("\t***********************************\n");
        printf("\t*******欢迎登入酒店管理系统********\n");
        printf("\t***********************************\n");
        printf("\t        0.登记入住(Insert)                 \n");
        printf("\t        1.查询房间的入住境况(Search)      \n");
        printf("\t        2.查询费用(Show)             \n");
        printf("\t        3.结账(jie)                   \n");
        printf("\t        4.退出程序                 \n");
        scanf("%d",&i);
        switch(i)
        {
           case 0:Insert();
                break;
           case 1:Search();
                    break;
           case 2:Show();
               break;
           case 3:jie();
               break;
           case 4:
               break;
           default:printf("错误选择:请重新选");break;
        }
        }while(i>=0&&i<=3);
    }
void load()
{
    FILE *fp;
    if((fp=fopen("ke.dat","rb"))==NULL)
    {
        printf("cannot open infile\n");
        return;
    }
    fread(&n,sizeof(struct people),1,fp);
    fread(ke,sizeof(struct people),n,fp);
    fclose(fp);
}
void save()
{
    FILE *fp;
    if((fp=fopen("ke.dat","wb"))==NULL)
    {
        printf("cannot open file\n");
            return;
    }
    fwrite(&n,sizeof(struct people),1,fp);
    fwrite(ke,sizeof(struct people),n,fp);
    fclose(fp);
}
void Insert()
{
    void load();
    int a,b=0;
    for(a=0;a<SIZE;a++)
    {
        if(room[a].kk==0)
          printf("可选房间:%d\n",room[a].id);
        else
        {
            printf("房间已住满:\n");
             return;
        }
    }
    printf("请选择你的房间\n");
    scanf("%d",&room[0].kk);
    printf("请输入你的名字:\n");
     scanf("%s",ke[0].name);
     printf("请输入你的身份证号码:");
    scanf("%s",ke[0].ID);
    while((strlen(ke[0].ID)!=18)&&(strlen(ke[0].ID)!=15))
    {
        printf("%d",strlen(ke[0].ID));
        printf("输入错误:请重新输入");
        printf("请输入你的身份证号码:");
        scanf("%s",ke[0].ID);
    }
    printf("请输入你的性别:\n");
    scanf("%s",ke[0].sex);
    printf("请输入入住天数:\n");
    scanf("%d",&ke[0].time);
    room[0].kk=1;
    n++;
    save();
}
void Search()
{
    int l;
    void look2();/*按名字查询*/
    void look1();/*按房间号码查询*/
    printf("请输入你要查询的方式:0按房间号码查询,1按名字查询\n");
    scanf("%d",&l);
    switch(l)
    {
    case 0: look1();break;
    case 1: look2();break;
    default:printf("输入错误:\n");break;
    }
}
void look1()
{
    int n,id;
    printf("请输入你的房间号码\n");
    scanf("%d",&id);
    for(n=0;n<SIZE;n++)
    {
        if(room[n].id==id)
        {
            printf("名字:%s\n",ke[n].name);
            printf("身份证号码:%s\n",ke[n]. ID);
            printf("性别:%s\n",ke[n].sex);
            break;
        }
    }
}
void look2()
{
    int n;
    char name[10];
    printf("请输入你的名字:\n");
    scanf("%s",name);
    for(n=0;n<SIZE;n++)
    {
        if(strcmp(name,ke[n].name)==0);
        {
            printf("你的身份证号码是:%s\n",ke[n].ID);
            printf("你的房间号码是:%d\n",room[n].id);
            printf("性别:%s",ke[n].sex);
            break;
        }
    }
}
void Show()
{
    int i=0;
    printf("请选择要查询人的房间号码:\n");
    scanf("%d",&room[0].kk);
    printf("入住的天数:%d\n",ke[0].time);
    printf("所用费用:%d\n",ke[0].time*room[0].jiage);
}
void jie()
{
    int j=0,k;
    printf("请输入你的房间号码\n");
    scanf("%d",&j);
    printf("是否退房,是按1,不是按2\n");
        scanf("%d",&k);
        switch(k)
        {
        case 1:room[j].kk=0;break;
        case 2:break;
        }
}
搜索更多相关主题的帖子: hotel 信息 include people 
2013-04-19 08:59
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
得分:9 
代码很长,运行什么问题没有说清楚

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2013-04-19 14:56
倵鄯
Rank: 2
等 级:论坛游民
帖 子:25
专家分:17
注 册:2012-11-8
得分:9 
void Insert()
 {
     void load();
     int a,b=0;
     for(a=0;a<SIZE;a++)
     {
         if(room[a].kk==0)
           printf("可选房间:%d\n",room[a].id);
         if(room[SIZE-1].kk==1)
             return;
     }
2013-04-20 00:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-404807-1-1.html




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

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