宾馆客房管理软件

 两个情况,一是我没用链表,二是入住登记时,选择继续登记是无法退出的
  1 #include<stdio.h>
  2 #include<string.h>
  3 #include<stdlib.h>
  4 #include<conio.h>
  5  
  6 int roomnum[5]={301,302,303,304,305};
  7  
  8  int menu();
  9 struct stu
 10 {
 11     char name[10];
 12     char sex[3];
 13     int empty=0;
 14  } Rooms[5];
 15  
 16  void  search()
 17  {
 18      printf("可以入住的房间有:"); 
 19      for(int i=0;i<5;i++)
 20      {
 21          if(Rooms[i].empty==0)
 22          {
 23              printf("%d  ",301+i); 
 24          } 
 25      }
 26      printf("
");
 27  }
 28 
 29 int check(int room)
 30 {
 31 
 32     if(room>305||room<301)
 33         return 0;
 34     if(Rooms[room-301].empty==0)
 35         return 1;
 36     else
 37         return 0;
 38 }
 39 
 40 void Getout()
 41 {
 42     system("cls");
 43     int getoutnum; 
 44     char a;
 45     printf("请输入退房顾客的房间号:
");
 46     scanf("%d",&getoutnum);
 47     printf("确认输入Y,返回主菜单输入N
"); 
 48     a=getch();
 49       if(a=='Y'||a=='y')
 50          {
 51              strcpy(Rooms[getoutnum-301].name,"");
 52              strcpy(Rooms[getoutnum-301].sex,"");
 53              Rooms[getoutnum-301].empty=0;
 54              menu();
 55          } 
 56      else if(a=='N'||a=='n')
 57         menu();    
 58 }
 59 
 60 int Findout()
 61 {
 62     system("cls");
 63     printf("提示:查询不守法,亲人两行泪
请输入你所需要查找的信息,
按姓名搜索在前面加1,按房间搜索在前面加2
"); 
 64      char a;    
 65      int k=0;
 66      char name[10];
 67      int room;
 68      a=getchar();
 69       if(a=='1')
 70          {
 71               scanf("%s",name);
 72              for(int i=0;i<5;i++)
 73              {
 74                  if(strcmp(Rooms[i].name,name)==0)
 75                  {
 76                      k=1;
 77                      printf("姓名:%s
性别:%s
房间号:%d

",Rooms[i].name,Rooms[i].sex,301+i);
 78                      printf("输入任意键回到主菜单");
 79                      getch(); 
 80                      getch();
 81                      menu();
 82                  }
 83              }
 84              if(k==0)
 85             {
 86                 printf("查无此人。");
 87                 menu();
 88             }
 89              
 90          }
 91      else if(a=='2')
 92         {
 93              scanf("%d",&room);
 94              if(Rooms[room-301].empty==1)
 95              {
 96                  printf("姓名:%s
性别:%s
房间号:%d

",Rooms[room-301].name,Rooms[room-301].sex,room);
 97                  printf("输入任意键回到主菜单");
 98                 getch(); 
 99                 getch();
100                  menu(); 
101             }
102             else
103             {
104                 printf("查无此人。");
105                 menu();
106             }
107         }
108     else
109     {
110         printf("输入错误,请重新输入:");
111         Findout(); 
112      } 
113 }
114  void Takein()
115  {
116      system("cls");
117      char a;
118      char name_a[10];
119      char sex_a[3];
120      search();
121      int room;
122      printf("请按如下格式输入:姓名:张三
性别:男
入住房号:301
"); 
123      printf("姓名:"); scanf("%s",name_a);
124      printf("性别:"); scanf("%s",sex_a);
125      printf("入住房号:"); scanf("%d",&room);
126      if(check(room)==1)
127      {
128          strcpy(Rooms[room-301].name,name_a);
129          strcpy(Rooms[room-301].sex,sex_a);
130          Rooms[room-301].empty=1;
131      }
132      else
133      {
134          printf("你的输入有误,请重新输入:
");
135          Takein();
136      }
137      printf("退出请输入Y,登记输入N
"); 
138      a=getch();
139       if(a=='Y'||a=='y')
140          menu();
141      else if(a=='N'||a=='n')
142         Takein();
143  }
144  
145 int menu()
146 {
147     system("cls");
148     printf(" 欢迎您,请输入对应数字进行操作
");
149     printf("***********1.入住办理***********
");
150     printf("***********2.退房办理***********
");
151     printf("***********3.人员搜索***********
"); 
152     char a=getch();
153     if(a=='1')
154         Takein();
155     else if(a=='2')
156         Getout();
157     else if(a=='3')
158         Findout();
159     else
160     {
161         printf("输入错误,请重新输入:");
162         menu();
163     }
164  } 
165  
166 int main()
167 {
168     menu();
169     return 0;
170  } 

好久没有敲代码了,月底的二级考试好虚啊

原文地址:https://www.cnblogs.com/ncoheart/p/10486100.html