0

I cant find the error in this code. I wrote it so it could accept the room ID, the name of the customer and phone number.

Then after accepting it should check whether that room is booked or not. After that it will save to a file. But the error comes when it asks if they want to book another room it automatically exits. But i want it to go back to the function if the reply was y. Here's the code. //this function is to check if the room Id entered is already booked or not int checkRoom(int rID, Rooms r){ room.open("Booked_Rooms", ios::in); if(room.is_open()){ while(!room.eof()){ if(rID==r.roomID){ room.close(); return 1; }else{ room.close(); return 0; } } }else { room.close(); return 0; } } //this is the booking function int checkRoom(int rID, Rooms r){ room.open("Booked_Rooms", ios::in); if(room.is_open()){ while(!room.eof()){ if(rID==r.roomID){ room.close(); return 1; }else{ room.close(); return 0; } } }else { room.close(); return 0; } }

27th Aug 2022, 4:05 PM
Vick
Vick - avatar
1 Odpowiedź
0
Sorry, i copied the same function twice. Here is the real booking function; void bookRoom(Rooms r){ char ch; int rm; system("cls"); room.open("Booked_rooms.txt", ios::app); if(room.is_open()){ do{ cout<<"\nEnter the room ID you want to book: "; cin>>rm; if(checkRoom(rm, r)!=1){ rm=r.roomID; cout<<"Enter guest name: "; gets(r.customerName); cin.ignore(); cout<<"Enter guest phone number: "; gets(r.phoneNumber); cin.ignore(); room<<"\n"<<r.roomID<<"\t"<<r.customerName<<"\t"<<r.phoneNumber; room.close(); cout<<"Would you like to book more rooms? (Y or y for yes and any other key for no)\n"; cin>>ch; } }while(ch=='y'||ch=='Y'); }else{ cout<<"\n\t\tFile is not opened!\n"; } }
27th Aug 2022, 4:08 PM
Vick
Vick - avatar