C++ not getting desired output

This is a part of my hospital management program. It's a function inside my appointment class to create a new appointment.

void app::create_app() //Create a new appointment
{
fstream f,g,h;
f.open("PAT.dat",ios::in|ios::binary);
g.open("STAFF.dat",ios::in|ios::binary);
h.open("APP.dat",ios::in|ios::binary|ios::out|ios::app);
int y,flag=1,choice;
char ch;
cost=500;
enter:
int flag1=1;
clrscr();
cout<<"\n\nEnter Patient ID";
cin>>id_p;
while(f.read((char*)&p,sizeof(p)))
{
if(p.returnp_id()==id_p)
{
flag1=0;
}
}
if(flag1==1)
{
cout<<"\nID does not exist";
cout<<"\nDo you want to try again?(Y/N)";
cin>>ch;
if(ch=='Y' || ch=='y')
goto enter;
else
exit(0);
}
cout<<"\nEnter Injury";
gets(injury);
cout<<"\nDoctor's list : "<<endl;
while(g.read((char*)&s,sizeof(s)))
{
if(s.returns_job()=='D' || s.returns_job()=='d')
{
cout<<endl;
s.returns1();
}
}
cout<<"\n\nEnter Doctor's ID ";
cin>>id_d;
cout<<"\nTime slots : "<<endl;
for(int i=1;i<11;i++)
{
{
cout<<"("<<i<<") "<<i<<"-"<<i+1;
cout<<endl;
}
}

cout<<"\nEnter desired time slot";
cin>>choice;
time=choice;
while(g.read((char*)&s,sizeof(s)))
{
if(s.returns_id()==id_d)
{
strcpy(doctor,s.name);
s.time[choice]=1;
}
}
randomize();
prev:
y=random(100); //Assigning random room number
h.seekg(0,ios::beg);
while(h.read((char*)&a,sizeof(a))) /*To check if room number
is already assigned */
{
if(a.returnroom()==y)
{
flag=0;
break;
}
}
if(!flag)
goto prev;
roomno=y;
cout<<"\nRoom Number : "<<roomno;
cout<<"\nCost : "<<cost;
f.close();
g.close();
h.close();
}

When i run the program & I input the details for one appointment, it displays it correctly. When i run the program again & input the details again, both the appointments are same except for the room number, even though I input different values.
Is it a problem with this function or is it a problem with some other function(display function)?
I use turbo c++ , please don't tell me to update it. My school uses outdated software.
Thanks for the help.
closed account (3TXyhbRD)
Use code tags
Not really enough code posted to determine where your problem is.

One problem that I do see is that when you prompt for the patient id, and it is not found, if the user answers yes to "Do you want to try again", you go back to the label enter: and proceed to try and read the patient file again, but it is at EOF. You don't reposition it back to the begining.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.


Topic archived. No new replies allowed.