this is a project made by me but its issue function is not working well instead of modifying and changing the value of issue to 2 it is adding another book with issue 2 in the file can some one correct it

// **library management** //
// **library members can add,delete,modify and search book** //
// **library members can operate users account** //
// **user can manage his record,issue and return a book** //
// **user can take only 1 book at a time** //

#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<process.h>
#include<math.h>
#include<dos.h>
#include<graphics.h>
#include<iomanip.h>
#include<stdlib.h>




void mainmenu(void);
 



struct libdate  // *defining date* //
{
int day;
int month;
int year;
};



struct address // *defining address* //
{
int hno ;
char area[100];
char city[100];
long int pincode;
};


class book    // *defining class book* //
{
int bcode;
char bname[100];
char author[100];
char category[100];
int issue;
libdate doe;                // *structure as class member* //

public :

void modify(void);

int getissue()
{
return issue;
}

void cissuey(void)
{
issue=1;
}

void cissuen(void)
{
issue=2;
}

void getdata(void)//*inputing data* //
{
 int gdriver = EGA, gmode = EGAHI;
   int bkcol, maxcolor,color;
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=6;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
cout<<"ENTER NAME:"<<endl;
gets(bname);
cout<<"ENTER CODE :"<<endl;
cin>>bcode;
cout<<"AUTHOR NAME :"<<endl;
gets(author);
cout<<"CATEGORY :"<<endl;
gets(category);
cout<<"DATE OF ENTRY "<<endl;
{
cout<<"DAY:"<<endl;
cin>>doe.day;
cout<<"MONTH :"<<endl;
cin>>doe.month;
cout<<"YEAR :"<<endl;
cin>>doe.year;
}
cout<<"the current status of the book is unissued by default so enter 1"<<endl;
cin>>issue;
}
void putdata(void)
{
 int gdriver = EGA, gmode = EGAHI;
   int bkcol, maxcolor,color;
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=6;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
cout<<" "<<bname<<" has the code "<<bcode<<endl;
cout<<" written by "<<author<<endl;
cout<<" is currently in the category "<<category<<endl;
cout<<" is entered in library on "<<doe.day<<"."<<doe.month<<"."<<doe.year<<endl;
cout<<" the current status of the book is "<<issue<<endl;
getch();
}

char*getauthname()
{
return author;
}

int getbcode(void)
{
return bcode;
}

};

book b1,b2;


void book::modify(void)             //*to modify a book record*//
{
int gdriver = EGA, gmode = EGAHI;
int bkcol, maxcolor,color;
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=2;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
cout<<" "<<bname<<" has the code "<<bcode<<endl;
cout<<"   written by "<<author<<endl;
cout<<"   is currently in the category "<<category<<endl;
cout<<"   is entered in library on "<<doe.day<<"."<<doe.month<<"."<<doe.year<<endl;
cout<<"   the current status of the book is "<<issue<<endl;

cout<<"enter new details"<<endl;
int mbc;
char an[100],cat[100],nm[100];
date dot;
cout<<"enter new details"<<endl;
cout<<"enter the new book code:(enter 1 to retain old one)"<<endl;
cin>>mbc;
cout<<"enter the new name:(press '.' to retain old one)"<<endl;
gets(nm);
cout<<"enter the new author:(press '.' to retain old one)"<<endl;
gets(an);
cout<<"enter the new category:(press '.' to retain old one)"<<endl;
gets(cat);
if(strcmp(nm,".")!=0)
strcpy(bname,nm);
if(strcmp(an,".")!=0)
strcpy(author,an);
if(strcmp(cat,".")!=0)
strcpy(category,cat);
if(mbc!=1)
bcode=mbc;
}


int searchbook(void)  //*to search a book*//
{
int gdriver = EGA, gmode = EGAHI;
int bkcol, maxcolor,color;
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=5;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
ifstream finbook;
finbook.open("lib.dat",ios::in|ios::binary);
finbook.seekg(0,ios::beg);
int n,m,choice;
char found='n';
char*mc;
cout<<"for searching through book code press 1 or by author name press 2"<<endl;
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"enter the book code to be searched"<<endl;
cin>>m;
while(!finbook.eof())
{
finbook.read((char*) &b1,sizeof(b1));
if(b1.getbcode()==m)
{
b1.putdata();
getch();
found='y';
return b1.getbcode();
finbook.close();
mainmenu();
}
}
if(found=='n')
cout<<"above book is not present in library!!"<<endl;
getch();
finbook.close();
return 0;
mainmenu();
}
case 2:
{
cout<<"enter the author's name for searching book"<<endl;
gets(mc);
while(!finbook.eof())
{
finbook.read((char*)&b1,sizeof(b1));
if(strcmpi(mc,b1.getauthname())==0)
{
b1.putdata();
getch();
found='y';
return b1.getbcode();
finbook.close();
mainmenu();
break;
}
}
if(found=='n')
cout<<"above book is not present in library!!"<<endl;
getch();
finbook.close();
mainmenu();
return 0;
}
}
}


void addbook(void)  //* add a book* //
{
int gdriver = EGA, gmode = EGAHI;
int bkcol, maxcolor,color;
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=10;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
ofstream foutbook("lib.dat",ios::app|ios::binary);
{
char ans='y';
while(ans=='y')
{
b1.getdata();
foutbook.write((char*) &b1,sizeof(b1));
cout<<"record added to library.\n"<<endl;
cout<<"do you want to enter more records?(y/n).."<<endl;
cin>>ans;
}
}

foutbook.close();
mainmenu();
}


void deletebook(void)  //*to delete an existing book* //
{
int gdriver = EGA, gmode = EGAHI;
int bkcol, maxcolor,color;
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=12;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
ifstream finbook;
ofstream foutbook;
finbook.open("lib.dat",ios::in);
foutbook.open("temp.dat",ios::out);
int bcode;
char found='f',confirm='n';
cout<<"enter the book code of the book which has to be deleted from library"<<endl;
cin>>bcode;
while(!finbook.eof())
{
finbook.read((char*) &b1,sizeof(b1));
if(b1.getbcode()==bcode)
{
b1.putdata();
found='t';
cout<<"want to delete,sure?(y/n).."<<endl;
cin>>confirm;
if(confirm=='n')
foutbook.write((char*) &b1,sizeof(b1));
}
else
foutbook.write((char*) &b1,sizeof(b1));
}
{
if(found=='f')
cout<<"record not found!!\n";
getch();
}
getch();
finbook.close();
foutbook.close();
remove("lib.dat");
rename("temp.dat","lib.dat"); //* old file is removed and temp is renamed *//
finbook.open("lib.dat",ios::in);
cout<<"record updated"<<endl;
cout<<"now the file contains"<<endl;
getch();
while(!finbook.eof())
{
finbook.read((char*)&b2,sizeof(b2));
if(finbook.eof())
break;
b2.putdata();
getch();

}
finbook.close();
mainmenu();
}


void modifybook(void) //* to modify a book record in library* //
{
int bcd;
long pos;
char found='f';
cout<<"enter the code of the book which has to be modified"<<endl;
cin>>bcd;
fstream fio("lib.dat",ios::in|ios::out|ios::binary);
fio.seekg(0,ios::beg);
while(!fio.eof())
{
pos=fio.tellg();
fio.read((char*)&b1,sizeof(b1));
if(b1.getbcode()==bcd)
{
b1.modify();
fio.seekg(pos); //*file pointer positioned to beginning position of record being modified,before writing back modified record*//
fio.write((char*)&b1,sizeof(b1));
found='t';
break;
}
}
if(found=='f')
cout<<"record not found!!"<<endl;
fio.seekg(0);
cout<<"now the file contains"<<endl;
while(!fio.eof())
{
fio.read((char*) &b2,sizeof(b2));
b2.putdata();
getch();
mainmenu();
}
}


void dispallbook(void)
{
ifstream finbook;
finbook.open("lib.dat",ios::in|ios::binary);
finbook.seekg(0,ios::beg);
cout<<"file contains"<<endl;
while(!finbook.eof())
{
finbook.read((char*)&b2,sizeof(b2));
if(finbook.eof())
{
break;
}
else
b2.putdata();
getch();
}
finbook.close();
mainmenu();
}


class account
{
int id;
char name[100];
int status;
address haddress;

public:
libdate doi,doer;

int bid;

libdate dor;

int getid(void)
{
return id;
}

int getstatus(void)
{
return status;
}

void cstatusy(void)
{
status=1;
}

void cstatusn(void)
{
status=2;
}


void enterdata(void)    //*entering the data of user*//
{
cout<<"enter the name of the user"<<endl;
gets(name);
cout<<"enter the library ID"<<endl;
cin>>id;
cout<<"enter the address of the user"<<endl;
{
cout<<"enter the house no."<<endl;
cin>>haddress.hno;
cout<<"enter the area in which the user is currently living"<<endl;
gets(haddress.area);
cout<<"enter the city in which the user is currently living"<<endl;
gets(haddress.city);
cout<<"enter the pincode of the city"<<endl;
cin>>haddress.pincode;
}
cout<<"enter the date of entry"<<endl;
{
cout<<"enter the day"<<endl;
cin>>doer.day;
cout<<"enter the month"<<endl;
cin>>doer.month;
cout<<"enter the year"<<endl;
cin>>doer.year;
}
cout<<"defualt value of status is 1 so enter 1"<<endl;
cin>>status;
}


void display(void)
{
int gdriver = EGA, gmode = EGAHI;
int bkcol, maxcolor,color;
  initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=2;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
cout<<name<<" has the library ID "<<id<<endl;
cout<<" who currently lives in "<<endl;
cout<<haddress.hno<<"  "<<haddress.area<<"  "<<haddress.city<<endl;
cout<<haddress.pincode<<endl;
}


void modifyuser(void)
{
cout<<name<<"has the id"<<id<<"living in"<<haddress.hno<<" "<<haddress.area<<" "<<haddress.city<<" "<<haddress.pincode<<endl;
cout<<"enter new details"<<endl;
char nm[100];
int idc;
address ha;
cout<<"enter the new name(press '.' to retain old one)"<<endl;
gets(nm);
cout<<"enter the new id(press 1 to retain old one)"<<endl;
cin>>idc;
cout<<"enter the new address"<<endl;
{
cout<<"enter the new homeno(press 2 to retain old one)"<<endl;
cin>>ha.hno;
cout<<"enter the new area(press '.' to retain old one)"<<endl;
gets(ha.area);
cout<<"enter the new city(press '.' to retain old one)"<<endl;
gets(ha.city);
cout<<"enter the new pincode.(press '3' to retain old one"<<endl;
cin>>ha.pincode;
}
if(strcmp(nm,".")!=0)
strcpy(name,nm);
if(strcmp(ha.area,".")!=0)
strcpy(haddress.area,ha.area);
if(strcmp(ha.city,"."))
strcpy(haddress.city,ha.city);
if(idc!=1)
id=idc;
if(ha.hno!=2)
haddress.hno=ha.hno;
if(ha.pincode!=3)
haddress.pincode=ha.pincode;
}
};
account s1,s2;


void adduser(void)    //*add a user*//
{
ofstream foutuser;
foutuser.open("user.dat",ios::app|ios::binary);
char ans='y';
while(ans=='y')
{
s1.enterdata();
foutuser.write((char*)&s1,sizeof(s1));
cout<<"user added to library"<<endl;
cout<<"do you want to enter more users?(y/n).."<<endl;
cin>>ans;
}
foutuser.close();
mainmenu();
}


void searchuser(void)  //*to search a user*//
{
ifstream finuser;
finuser.open("user.dat",ios::in|ios::binary);
finuser.seekg(0,ios::beg);
int uid;
char found='n';
cout<<"enter the library ID of the user to be searched"<<endl;
cin>>uid;
while(!finuser.eof())
{
finuser.read((char*)&s1,sizeof(s1));
if(s1.getid()==uid)
{
s1.display();
getch();
found='y';
mainmenu();
}
}
if(found=='n')
cout<<"user not registered"<<endl;
getch();
finuser.close();
mainmenu();
}


void deleteuser(void)
{
ifstream fio("user.dat",ios::in|ios::binary);
ofstream file("temp.dat",ios::out|ios::binary);
int uid;
char found='f',confirm='n';
cout<<"enter the ID of the user whom you want to delete"<<endl;
cin>>uid;
while(!fio.eof())
{
fio.read((char*) &s1,sizeof(s1));
if(s1.getid()==uid)
{
s1.display();
found='t';
cout<<"want to continue sure(y/n).."<<endl;
cin>>confirm;
if(confirm=='n')
file.write((char*)&s1,sizeof(s1));
}
else
file.write((char*)&s1,sizeof(s1));
}
if(found=='f')
cout<<"user not found!!"<<endl;
getch();
fio.close();
file.close();
remove("user.dat");
rename("temp.dat","user.dat");
fio.open("lib.dat",ios::in|ios::binary);
cout<<"record updated"<<endl;
cout<<"now the file contains"<<endl;
getch();
while(!fio.eof())
{
fio.read((char*) &s2,sizeof(s2));
if(fio.eof())
break;
s2.display();
getch();
}
mainmenu();
fio.close();
}


void modifyaccount(void)
{
fstream fio("user.dat",ios::in|ios::out|ios::binary);
int uid;
long pos;
char found='f';
fio.seekg(0,ios::beg);
cout<<"enter the id of the user whose record is to be modified"<<endl;
cin>>uid;
while(!fio.eof())
{
pos=fio.tellg();
fio.read((char*)&s1,sizeof(s1));
if(s1.getid()==uid)
{
s1.modifyuser();
fio.seekg(pos);
fio.write((char*)&s1,sizeof(s1));
found='t';
break;
}
}
if(found=='f')
cout<<"record not found!!"<<endl;
fio.seekg(0);
cout<<"now the user file contains"<<endl;
while(!fio.eof())
{
fio.read((char*)&s2,sizeof(s2));
s2.display();
getch();
}
mainmenu();
fio.close();
}

void issuebook(void)
{
char ch;
int m,n,uid;
int rec1=0,rec2=0;
libdate temp;
cout<<"Enter ur library ID"<<endl;
cin>>uid;
fstream iofile("user.dat",ios::in|ios::app|ios::binary);
fstream ifile("lib.dat",ios::in|ios::app|ios::binary);
while(!iofile.eof())
{
if(iofile.eof())
{
mainmenu();
}
iofile.read((char*)&s1,sizeof(s1));
rec1++;
if(uid==s1.getid())
{
n=s1.getstatus();
if(n==2)
{
cout<<"you already have issued one book"<<endl;
getch();
mainmenu();
}
else
cout<<".....Search the book you want to issue"<<endl;
getch();
int bbcode = searchbook();
while(bbcode!=0)
{
cout<<"are u sure u want to take this book(y/n)"<<endl;
cin>>ch;
if(ch=='y'||ch=='Y')
{
while(!ifile.eof())
{
if(ifile.eof())
{mainmenu();}
ifile.read((char*)&b1,sizeof(b1));
rec2++;
if(bbcode==b1.getbcode())
{
m=b1.getissue();
if(m==2)
{
cout<<"Already issued...\n";
mainmenu();
}
else
s1.bid=bbcode;
cout<<"ENTER THE DATE OF ISSUE"<<endl;
{
cout<<"ENTER THE DAY"<<endl;
cin>>temp.day;
cout<<"ENTER THE MONTH"<<endl;
cin>>temp.month;
cout<<"ENTER THE YEAR"<<endl;
cin>>temp.year;
}
s1.doi=temp;
b1.cissuen();
s1.cstatusn();
iofile.seekg((rec1-1)*sizeof(s1),ios::beg);
ifile.seekg((rec2-1)*sizeof(b1),ios::beg);
ifile.write((char*)&b1,sizeof(book));
iofile.write((char*)&s1,sizeof(account));
cout<<" Status updated..\n";
getch();
}
}
ifile.close();
mainmenu();
}
else
{
cout<<"SORRY u can search some other time"<<endl;
ifile.close();
iofile.close();
getch();
mainmenu();
}
}
}
else
cout<<"WRONG ID ENTERED!!!..PLZ ENTER YOUR VALID ID"<<endl;
iofile.close();
getch();
mainmenu();
}
iofile.close();
}





void returnbook(void)                  //* to return a book from user * //
{
int uid,bbcode;
int m;
libdate temp;
m=b1.getissue();
cout<<"ENTER UR LIBRARY ID"<<endl;
cin>>uid;
fstream iofile("user.dat",ios::in|ios::app|ios::binary);
fstream ifile("lib.dat",ios::in|ios::app|ios::binary);
while(iofile)
{
iofile.read((char*)&s1,sizeof(s1));
if(uid==s1.getid())
{
cout<<"valid ID....."<<endl;
cout<<"enter the book code of the book u want to return"<<endl;
cin>>bbcode;
while(ifile)
{
ifile.read((char*)&b1,sizeof(b1));
if(bbcode==b1.getbcode())
{
cout<<"book found checking its status"<<endl;
getch();
if(m==2)
{

cout<<"calculating fine"<<endl;
{
int m,n,p;
if(s1.dor.year==s1.doi.year)
{
if(s1.dor.month==s1.doi.month)
{
if(s1.dor.day-s1.doi.day<4)
{
cout<<"you do not have to pay any fine"<<endl;
}
else
m=s1.dor.day-s1.doi.day;
cout<<"you have to pay a fine of rs."<<m;
}
else
{
if(s1.dor.month-s1.doi.month==1)
{
n=30-s1.doi.day;
if(n+s1.dor.day<4)
{
cout<<"you do not have to pay any fine"<<endl;
}
else
cout<<"you have to pay a fine of rs."<<n+s1.dor.day<<endl;
}
else
cout<<"you have to pay a fine of rs. 200"<<endl;
}
}
else
{
if(s1.dor.year-s1.doi.year==1)
{
if((s1.doi.month==12)&&(s1.dor.month==1))
{
p=30-s1.doi.day;
if(p+s1.dor.day<4)
{
cout<<"you do not have to pay any fine"<<endl;
}
else
cout<<"you have to pay the fine of"<<p+s1.dor.day;
}
else
cout<<"you have to pay the fine of rs. 200"<<endl;
}
else
cout<<"you have to pay the fine of rs. 500"<<endl;
}
}
cout<<"now changing the status of this book"<<endl;
getch();
b1.cissuey();
s1.cstatusy();
cout<<"ENTER THE DATE OF RETURN"<<endl;
{
cout<<"ENTER THE DAY"<<endl;
cin>>temp.day;
cout<<"ENTER THE MONTH"<<endl;
cin>>temp.month;
cout<<"ENTER THE YEAR"<<endl;
cin>>temp.year;
}
s1.dor=temp;
ifile.write((char*)&b1,sizeof(b1));
iofile.write((char*)&s1,sizeof(s1));
mainmenu();
}
else
cout<<"error!this book is free to issue"<<endl;
getch();
mainmenu();
}
else
cout<<"u haven't issued this book kindly check the book id again"<<endl;
getch();
mainmenu();
}
ifile.close();}
else
cout<<"WRONG USER ID ENTRED CHECK AGAIN"<<endl;
getch();
mainmenu();
}
iofile.close();
}

void record(void)
{
int m;
int uid,ubcode;
m=s1.getstatus();
fstream iofile("user.dat",ios::in|ios::app|ios::binary);
while(iofile)
{
iofile.read((char*)&s1,sizeof(s1));
cout<<"Enter your valid library ID"<<endl;
cin>>uid;
if(uid==s1.getid())
{
cout<<"valid ID....checking ur record.."<<endl;
getch();
if(m==1)
{
cout<<"you have not taken any book currently"<<endl;
getch();
mainmenu();
}
else
{
cout<<"you have taken the following book"<<endl;
getch();
ubcode=s1.bid;
ifstream ifile;
ifile.open("lib.dat",ios::in|ios::binary);
ifile.read((char*)&b1,sizeof(b1));
if(ubcode==b1.getbcode())
{
b1.putdata();  
getch();
}
else
cout<<"!!ERROR!!"<<endl;
getch();
mainmenu();
}
}
else
cout<<"WRONG LIBRARY ID PLZ TRY AGAIN"<<endl;
getch();
mainmenu();
}
iofile.close();
}



void dispalluser(void)
{
ifstream fio("user.dat",ios::in|ios::binary);
fio.seekg(0,ios::beg);
cout<<" the file contains"<<endl;
while(!fio.eof())
{
fio.read((char*)&s1,sizeof(s1));
if(fio.eof())
{
break;
}
else
s1.display();
getch();
}
fio.close();
}



void mainmenu(void)
{
int m,n,mn,ch;
int ans;
	 int gdriver = EGA, gmode = EGAHI;
   int bkcol, maxcolor,color;
   char msg[80];
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=4;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);

	  gotoxy(25,5);
	  cout<<"M A I N   M E N U";
	  gotoxy(17,10);
	  cout<<"1. BOOKS MENU";
	  gotoxy(17,12);
	  cout<<"2. ACCOUNT MENU";
	  gotoxy(17,14);
	  cout<<"3. USER MENU";
	  gotoxy(17,16);
	  cout<<"4. EXIT";
	  gotoxy(40,24);
	      cout<<"Enter Option(1-4):";

cin>>m;

switch(m)
{

case 1:
{
 int gdriver = EGA, gmode = EGAHI;
   int bkcol, maxcolor,color;
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=2;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
gotoxy(20,4);
cout<<" 1 : ADD A BOOK";
gotoxy(20,6);
cout<<" 2 : SEARCH A BOOK";
gotoxy(20,8);
cout<<" 3 : MODIFY A BOOK'S RECORD";
gotoxy(20,10);
cout<<" 4 : DELETE";
gotoxy(20,12);
cout<<" 5 : DISPLAY ALL ";
gotoxy(20,14);
cout<<" 6 : RETURN TO MAIN MENU"<<endl;
gotoxy(20,16);
cout<<"ENTER OPTION(1-7)"<<endl;
cin>>n;

switch(n)
{
case 1:
{
addbook();
break;
}
case 2:
{
searchbook();
break;
}
case 3:
{
modifybook();
break;
}
case 4:
{
deletebook();
break;
}
case 5:
{
dispallbook();
break;
}
case 6:
{
mainmenu();
}
default: cout<<"INVALID ENTRY!!"<<endl;
}
break;
}

case 2:
{
 int gdriver = EGA, gmode = EGAHI;
   int bkcol, maxcolor,color;
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=11;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
cout<<"1 : CREATE NEW ACCOUNT"<<endl;
cout<<"2 : SEARCH A USER"<<endl;
cout<<"3 : MODIFY A USER'S INFO"<<endl;
cout<<"4 : DELETE A USER"<<endl;
cout<<"5 : DISPLAY ALL USERS"<<endl;
cout<<"6 : RETURN TO MAIN MENU"<<endl;
cout<<"ENTER OPTION(1-6)"<<endl;
cin>>mn;

switch(mn)
{

case 1:
{
adduser();
break;
}
case 2:
{
searchuser();
break;
}
case 3:
{
modifyaccount();
break;
}
case 4:
{
deleteuser();
break;
}
case 5:
{
dispalluser();
break;
}
case 6:
{
mainmenu();
}
default : cout<<"INVALID ENTRY!!"<<endl;
}
break;
}

case 3:
{
 int gdriver = EGA, gmode = EGAHI, errorcode;
   int bkcol, maxcolor,color;
   initgraph(&gdriver, &gmode,"");
   maxcolor = getmaxcolor();
	  bkcol=maxcolor=9;
	  setbkcolor(bkcol);
	  color=maxcolor;
	  setcolor(color);
cout<<"welcome to user's manual"<<endl;
cout<<"1: ISSUE BOOK"<<endl;
cout<<"2: RETURN BOOK"<<endl;
cout<<"3: CURRENT RECORD"<<endl;
cout<<"4:RETURN TO MAIN MENU"<<endl;
cout<<"ENTER OPTION(1-4)"<<endl;
cin>>ch;
switch(ch)
{
case 1:
{
issuebook();
break;
}
case 2:
{
returnbook();
break;
}
case 3:
{
record();
break;
}
case 4:
{
mainmenu();
}
default: cout<<"INVALID ENTRY!!"<<endl;
}
break;
}

case 4:
{
cout<<"press any key to continue"<<endl;
exit(0);
break;
}
default:cout<<"INVALID ENTRY!!"<<endl;
}
}



void main()
{
clrscr();
mainmenu();     
getch();
}

Recommended Answers

All 10 Replies

Well, I don't see a function called issue(). I do see a function called issuebook(). Is that the one you are refering to?

While waiting for reply I offer the following in terms of general recommendations.

1) Don't use void as the return type of main(), even if your compiler let's you. It's not standard and it's one more keystroke than typing int.

2) Don't use the return value of eof() as the controlling value of a loop. Sooner or later it is going to create problems, such as looping through a sequence of code one too many times which may cause duplication of the last set of valid input and may overwrite an array, etc.

3) you have declared two mainmenu() functions. Erase the first one at the top of the code as it does nothing.

4) hopefully you indent your code when writing it (if not, do so!) and the indentation was lost when you posted it here because of the way the board works. To prevent that from happening in the future read about using code tags around the code posted to maintain the indentation, etc. Information about using code tags is in the watermark before you start typing into the Message box, and even better, in one of the announcements at the top of this board.
Many people here won't read code if not indented, especially if it's long, because it's just too hard to do comfortably.

4) Try to be more specific when asking questions---what isn't working right about the function? And try to be more specific about the code you post. Hopefully if you ask a specific enough question you can post just the function in question and not the whole program. If additional code is requested by a respondent, then you can post it.

5) Comment your code. It will help you decode it and it will help people reading your code figure out what you are actually trying to do instead of trying to make a guess.

I agree with all of Lerner's comments.

I decided your problem looked like fun so I decided to try and get it to compile on my system.

What Compiler are you using?

What is your target Operating System?

(My compiler didn't have support for the BGI graphics so I had to comment it all out -- and fix several other things that relied on it working.)

First major oops is that you keep calling mainmenu() to return to the main menu. That does NOT return to the main menu, it calls a brand new mainmenu that in theory would return to where you called it from, but your mainmenu() as coded will never return.

Every time you make a menu selection and return to the main menu your stack gets a little smaller, eventually (if you ran the program long enough) you would run out and the program will fault.

I'll keep converting and trying to get it to compile / run. But a good specific question would be very helpful. (Something like "When I select ___ from the ___ menu, I expected to see ___ but I see ___ instead. What did I miss?" gives good location and information.) The better the information you give the more likely you are to get a useful answer.

ok this is actually my 1st c++ prog.This is the issuebook function some how i have corrected the first mistake.
IT takes an user id reads the user file and check if the status( a data member ) is 1 or not if 1 it allow u to issue a book. then the function search book search the books and return its code to bbcode if search is unsuccessful than 0 is returned now after the book is issued the value of issue of book becomes 2 and value of status of user becomes 2.

now the value of issue is showing to be 2 but not that of status of user it is still showing 1.

void issuebook(void)
{
char ch;
int m,n,uid;
int rec1=0,rec2=0;
libdate temp;
cout<<"Enter ur library ID"<<endl;
cin>>uid;
fstream iofile("user.dat",ios::in|ios::out|ios::binary);
fstream ifile("lib.dat",ios::in|ios::out|ios::binary);
while(!iofile.eof())
{   
long pos=iofile.tellg();
iofile.read((char*)&s1,sizeof(s1));
rec1++;
if(uid==s1.getid())
{
n=s1.getstatus();
if(n==2)
{
cout<<"you already have issued one book"<<endl;
getch();
mainmenu();
}
else
cout<<".....Search the book you want to issue"<<endl;
getch();
int bbcode = searchbook();
while(bbcode!=0)
{
cout<<"are u sure u want to take this book(y/n)"<<endl;
cin>>ch;
if(ch=='y'||ch=='Y')
{
while(!ifile.eof())
{
ifile.read((char*)&b1,sizeof(b1));
rec2++;
if(bbcode==b1.getbcode())
{
m=b1.getissue();
if(m==2)
{
cout<<"Already issued...\n";
mainmenu();
}
else
s1.bid=bbcode;
b1.cissuen();
s1.cstatusn();
cout<<"enter date of issue"<<endl;
{
cout<<"enter day"<<endl;
cin>>temp.day;
cout<<"enter month"<<endl;
cin>>temp.month;
cout<<"enter year"<<endl;
cin>>temp.year;
}
s1.doi=temp;
cout<<"updating users record"<<endl;
iofile.seekg(pos);
iofile.write((char*)&s1,sizeof(s1));
cout<<"updating books record"<<endl;
ifile.seekg((rec2-1)*sizeof(b1),ios::beg);
ifile.write((char*)&b1,sizeof(book));
cout<<" Status updated..\n";
getch();
}
}
ifile.close();
mainmenu();
}
else
{
cout<<"SORRY u can search some other time"<<endl;
ifile.close();
iofile.close();
getch();
mainmenu();
}
}
}
else
cout<<"WRONG ID ENTERED!!!..PLZ ENTER YOUR VALID ID"<<endl;
iofile.close();
getch();
mainmenu();
}
iofile.close();
}

Did you see the note about code tags?

When posting c++ code, please use c++ code tags
[code=c++] // Your code here

[/code]

You're not using the same style of seek for both files.

iofile.seekg(pos);
    ifile.seekg((rec2-1)*sizeof(b1),ios::beg);

The user file never gets closed.

ifile.close();
mainmenu();

You're still calling for a new mainmenu().

You didn't answer the Compiler and O/S questions.

read your code and have some personal suggestions about that:
is it better to have different classes like

class libmembers 
{
}
class libusers
{
}
class book
{
}

??

#
fstream iofile("user.dat",ios::in|ios::out|ios::binary);
#
fstream ifile("lib.dat",ios::in|ios::out|ios::binary);

see i m using the same way to open two files

#
cout<<"updating users record"<<endl;
#
iofile.seekg(pos);
#
iofile.write((char*)&s1,sizeof(s1));
#
cout<<"updating books record"<<endl;
#
ifile.seekg((rec2-1)*sizeof(b1),ios::beg);
#
ifile.write((char*)&b1,sizeof(book));

and the same way to write into files that is the pos will tell the address before reading the record and rec2 just increments value after reading each record so each time i sets the put pointer at the beginning of record.
But whenever i run the prog the book file is working correctly and the value of issue in book is changing to 2 but it is not writing anything in user record.
i then closed the iofile and opened a new file wofile in output mode only so it just erased all the previos record so if i just use it for 1 user the program is correct but for multiple user it is not.

and murtan i have to pasted some special files named bgifiles in the include folder ( i had taken them from school u can search net ) to enable graphics

You may have BGI files, but I didn't and so I had to modify the code to get it to compile. I'm running Windows, and as I understand it, BGI is not compatible.

Maybe if I make the questions BIG you'll answer them:

WHAT COMPILER ARE YOU USING?

WHAT OPERATING SYSTEM ARE YOU RUNNING ON?

The point I was making about the seeks, was that one is using ios::beg and the other wasn't, it may be the default, but you made a point of passing it to one and not to the other.

Why use tellg to get position for one file and use a record counter and a mulitply for the other file? Why not use the same method for both files?

(I'm picking at differences between the two because you say one works and the other doesn't.)

If I've been reading through the code correctly, it is designed to loan (issue) one book (that has not already been issued) to the member (that does not already have a book). Is there any sense or record of which member has which book?

Would it ever be desired to issue more than one book to a member? (I know my local library will :) )

This application seems like it would lend itself well to a database, might that be an option for ongoing development?

I took your last issue book posted and I'm trying to work with it, but the BGI conversion and the getch() conversions as well as re-writing to not call mainmenu() again are painful.

If you want to modify your program so that mainmenu is a loop, you could use the following as a basis if you like. If you insist on calling mainmenu() from wherever you feel like in your code, I think I'm done trying to take your 'new' code to put in my test application.

My version of your main menu (its not as pretty, but it compiles and runs.)

void mainmenu()
{
	int m;
	//int gdriver = EGA, gmode = EGAHI;
	//int bkcol, maxcolor,color;
	//char msg[80];
	//initgraph(&gdriver, &gmode,"");
	//maxcolor = getmaxcolor();
	//bkcol=maxcolor=4;
	//setbkcolor(bkcol);
	//color=maxcolor;
	//setcolor(color);

	m = 0;
	while (m != 4)
	{

		//gotoxy(25,5);
		cout << "\n\nM A I N   M E N U\n";
		//gotoxy(17,10);
		cout<<"1. BOOKS MENU\n";
		//gotoxy(17,12);
		cout<<"2. ACCOUNT MENU\n";
		//gotoxy(17,14);
		cout<<"3. USER MENU\n";
		//gotoxy(17,16);
		cout<<"4. EXIT\n";
		//gotoxy(40,24);
		m = inputInt("Enter Option(1-4): ", 1, 4);

		switch(m)
		{
		case 1:
			booksmenu();
			break;
		case 2:
			accountmenu();
			break;
		case 3:
			usermenu();
			break;
		case 4:
			break;
		default:
			cout << m << " is not a valid option" << endl;
		}
	}
}

inputInt is a helper function I wrote, I'm not entirely happy with it, but I was having problems with input stream status so I made a few functions to help me out:

// Prompt for and accept an integer value. Enforce the specified range on the input
int inputInt(char const * prompt, int minval, int maxval)
{
	int rval = -1;
	std::string tmp;

	for (;;)
	{
		std::cout << prompt;
		getline(std::cin, tmp);
		rval = atol(tmp.c_str());
		if (rval < minval)
		{
			std::cout << rval << "is below the minimum (" << minval << ")" << std::endl;
		} 
		else if (rval > maxval)
		{
			std::cout << rval << "is above the maximum (" << maxval << ")" << std::endl;
		} 
		else 
		{
			break;
		}
	}
	return rval;
}

(This code is from another .cpp file that does not have a using namespace std; )

well the pos will tell the address of pointer before reading so setting it their and increming in rec++ is just diff method but both fetch same results i used this pos to print the value as i was checking whether it is working right or not so i just printed cout<<pos and then printed cout<<(rec1-1)*sizeof(s1) so both gives same value.


i have just modified the code as opening the iofile in ifstream then close it and open a new file wwfile in output mode so it just erases all the record barring the one using it
but it will work coz atleast i can show the examiner that my program is working :P
i m using window xp i m not getting what do u mean by compiter but i m using turbo c++ version 3.0

this is the boundation of program user can issue only 1 book at a time.

The iofile.seekg(pos) appears to be an offset seek (as in it seeks forward from the current file location by default).

You might try iofile.seekg(pos, ios::beg); to see if the in-place updates work.

PS- turbo c++ 3.0 is VERY old, you might consider upgrading to a more modern compiler. One option would be Visual C++ Express (It is free to download and I believe it is free to use -- as long as you don't make money with it.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.