This is my code. I want to check whether or not the value the user entered for idnum
already exists as the idnum
for any other patient in the file "patient.dat"
. This code doesn't show any error but it doesn't work logically either. I'm using the TurboC 7 compiler.
void patient::idnum(patient p)
{
do
{
clrscr();
int found4=0;
cout<<"enter a 4 digit id number";
cin>>idno;
ofstream f3;
ifstream f4;
f4.open("patient.dat",ios::in);
f4.seekg(0);
while(!f4.eof())
{
f4.read((char*)&p,sizeof(p));
if(p.getid()==idno)
cout<<" id number already in use.. try again";
else
found4=1;
}
if(found4==1)
{
cout<<"valid entry... pls continue";
f3.open("patient.txt",ios::out|ios::app);
f3.write((char*)&p,sizeof(p));
f3.close();
getch();
}
} while(p.getid()!=idno);
}