code not working the way i want it to! pls reply fast!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#include<process.h>
#include<stdio.h>
#include<iostream.h>
#include<dos.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>
#include<fstream.h>
#include<math.h>
struct DATE
{
 int date;
 int month;
 int year;
};
struct room
{
 int no;
 char status;
};
long Subdate(DATE A,DATE B);
class guest
{
 int roomno;
 char name[20];
 char nation[10];
 char phno[10];
 DATE start,end;
 float cost;
 public:
 guest()
 {
  roomno=0;
  strcpy(name,"NULL");
  strcpy(nation,"NULL");
  strcpy(phno,"-");
  cost=500.00;
 }
 long retrno(){ return roomno;}
 void book();
 void checkout();
 void Bill(long a)
 {
  cost*=a;
 }
 void Display()
 {
  cout<<"\n\n"<<setw(10)<<roomno<<setw(10)<<name<<setw(10)<<nation<<setw(2)<<start.date<<'.'<<setw(2)<<start.month<<'.'<<setw(4)<<start.year;
 }
};
 void guest::book()
 {
  room R;
  fstream f("Room.dat",ios::binary|ios::in|ios::out);
  if(!f)
  cout<<"\n Room File Error";
  else
  {
   int count=0;
   cout<<"\nEnter name: ";
   gets(name);
   cout<<"\nEnter nationality: ";
   gets(nation);
   cout<<"\nEnter phone no.: ";
   gets(phno);
   cout<<"\nEnter date of check-in    ";
   cin>>start.date>>start.month>>start.year;
   while(f.read((char*)&R,sizeof(R)))
   {
    if(R.status=='V')
    {
     count++;
     roomno=R.no;
     cout<<"\n\n New Guest "<<name<<"'s Room Number Is "<<roomno;
     f.seekg(-1*sizeof(room),ios::cur);
     R.status='O';
     f.write((char*)&R,sizeof(R));
     break;
    }
   }
   f.close();
   if(count==1)
   {
    cout<<"\n\n ENJOY YOUR STAY AT OUR HOTEL";
    ofstream fout("Guest.dat",ios::binary|ios::app);
    fout.write((char*)this,sizeof(guest));
   }
   else
   cout<<"\n\n SORRY! NO ROOMS AVAILABLE";
 }
}
void guest::checkout()
{
  room R;
  fstream f("Room.dat",ios::binary|ios::in|ios::out);
  if(!f)
  cout<<"\nRoom File Error";
  else
  {
   while(f.read((char*)&R,sizeof(R)))
   {
    if(roomno==R.no)
    {
     f.seekg(-1*sizeof(room),ios::cur);
     R.status='V';
     f.write((char*)&R,sizeof(R));
     cout<<"\nEnter date of checkout";
     cin>>end.date>>end.month>>end.year;
     long no=Subdate(end,start);
     Bill(no);
     break;
    }
   }
    char n[10];
    cout<<"\n\nYou have to pay Rs."<<cost;
    cout<<"\n\nEnter your bank account number";
    cin>>n;
    cout<<"\n\n THANK YOU WE HAVE RECIEVED YOUR MONEY";
    cout<<"\n\n HOPE YOU ENJOYED YOUR STAY WITH US";
    cout<<"\n\n PLEASE COME AGAIN";
    ifstream fin("Guest.dat",ios::binary);
    ofstream fout("Temp.dat",ios::binary);
    guest S;
    while(fin.read((char*)&S,sizeof(S)))
     if(S.roomno!=roomno)
      fout.write((char*)&S,sizeof(S));
   fin.close();
   fout.close();
   remove("Guest.dat");
   rename("Temp.dat","Guest.dat");
  }
 }
 long Subdate(DATE A,DATE B)
 {
  int a=0;
  while((B.date!=A.date)||(B.month!=A.month)||(B.year!=A.year))
  {
   if(B.date==31&&B.month==12)
   {
    B.year++;
    B.date=1;
    B.month=1;
    a++;
   }
   else if(((B.month==1)||(B.month==3)||(B.month==5)||(B.month==7)||(B.month==8)||(B.month==10))&&(B.date==31))
   {
    B.month++;
    B.date=1;
    a++;
   }
   else if(((B.month==4)||(B.month==6)||(B.month==9)||(B.month==11))&&(B.date==30))
   {
    B.month++;
    B.date=1;
    a++;
   }
   else if((B.month==2)&&(B.year%4==0)&&(B.date==29))
   {
    B.month++;
    B.date=1;
    a++;
   }
   else if((B.month==2)&&(B.date==28))
   {
    B.month++;
    B.date=1;
    a++;
   }
   else
   {
    B.date++;
    a++;
  }
}
  return abs(a+1);
}
void main()
{
  int ch;
  clrscr();
  room R[500];
  for(int i=0;i<500;i++)
  {
   R[i].no=i+1;
   R[i].status='V';
  }
  ofstream fout("Room.dat",ios::binary);
  for(i=0;i<500;i++)
  fout.write((char*)&R[i],sizeof(room));
  gotoxy(20,20);
  cout<<" HOTEL MANAGEMENT PROJECT  ";
  gotoxy(30,30);
  cout<<" Done by S.Vignesh, Akshay & Arun Alexander ";
  gotoxy(10,40);
  cout<<" Press any key to continue.....";
  getche();
  Start:
  clrscr();
  cout<<"\n\n\t\t\t MENU";
  cout<<"\n\n1.Intro";
  cout<<"\n\n2.Book";
  cout<<"\n\n3.Checkout";
  cout<<"\n\n4.Display All Guests";
  cout<<"\n\n5.Exit";
  cin>>ch;
  switch(ch)
  {
   case 1:clrscr();
	  cout<<" \n\nThis is a project on hotel management system ";
	  cout<<" \n\nIn this project, rooms are booked and when checking out";
	  cout<<" \n\nthis system generates a bill which is calculated on the";
	  cout<<" \n\nbasis of number of days times the days stayed which is ";
	  cout<<" \n\ncalculated taking the date of arrival and the date of ";
	  cout<<" \n\ndeparture. Since this hotel is still under construction";
	  cout<<" \n\nmany features like restaurant and bar are not there and";
	  cout<<" \n\nthey are soon to be implemented plus more rooms ";
	  cout<<" \n\nPress any key to return ";
	  getche();
	  goto Start;
   case 2:guest G;
	  G.book();
	  cout<<"\n Press Any Key To Return To Main Menu";
	  getche();
	  goto Start;
   case 3:long n;
	  rnoenter:
	  cout<<"\n Enter Your Room Number";
	  cin>>n;
	  ifstream fin("Guest.dat",ios::binary);
	  while(fin.read((char*)&G,sizeof(G)))
	  if(G.retrno()==n)
	  {
	   G.checkout();
	   cout<<"\n Deleted";
	  }
	  else
	  {
	   cout<<"\n That's a vacant room. Enter correctly";
	   goto rnoenter;
	  }
	  cout<<"\nPress Any Key To Return The Main Menu";
	  getche();
	  goto Start;
   case 4:guest G1;
	  cout<<"\n\t\tLIST OF ALL GUESTS";
	  cout<<'\n';
	  cout<<setw(10)<<"roomno"<<setw(10)<<"name"<<setw(10)<<"nation"<<setw(12)<<"date booked";
	  ifstream fin2("Guest.dat",ios::binary);
	  while(fin2.read((char*)&G1,sizeof(G1)))
	  G1.Display();
	  cout<<"\nPress Any Key To Return The Main Menu";
	  getche();
	  goto Start;
   case 5:cout<<"\n Exiting..........";
	  delay(5000);
	  exit(0);
   default:goto Start;
 }
}




This is a project on hotel management!
the problem is that when i book a room, the computer should generate a room number for the guest in such a way that for the first guest room number is 1 for second 2 etc... but for 2nd and successive guests also it gives the room number as 1 only! What could be the problem? Help Please!
Last edited on
[code] "Please use code tags" [/code]
http://cplusplus.com/forum/articles/40071/#msg216313
done.
no reply? :|
Please read the link. Some comments will be good too.

Also, change your book.
_It is outdated. The header are <iostream>, <cmath>, etc.
_It does not follow the standard. ( main must return int )
_It teachs dangerous things. (never use gets() )

Try to separate the interface from the program.
And try to not use goto
Topic archived. No new replies allowed.