Library system through filling

Hello Everyone...
I have been trying to do my summer project and have encountered a problem. I am going to paste my code in here and looking for some help. This program is basically through double link list which creates, find, issue, read and delete the book's record kept in a text file. I am having the following problems.
In findbook function : when the book's id is given it represents the information rather than just showing the only information belonging to the book id.
In Delete Function : I cannot delete a book's record in a text file whyle it says that the book has been deleted.
This is my first time. I shall be very thank full to you for providing me some help.

# include <iostream>
# include <fstream>

using namespace std;

struct book
{
char bname[20];
char bedition[20];
char bprice[20];
int bid;
struct book *pre;
struct book *next;

};
book *head=NULL,*p,*q,*r;

struct buyer
{
char name [20];
int cnic ;
char selectedbook [20];
};
buyer *head2=NULL,*x,*y,*z;

int size[25],num,info;
char name[50];


void createbook ();
void findbook ();
void issuebook ();
void deletebook ();
void readbook ();

int main ()
{
M:
char choice;
cout <<"\n\n\t\t\tPress B To Create A Book.\n";
cout <<"\n\n\t\t\tPress F To Find A Book.\n";
cout <<"\n\n\t\t\tPress I To Issue A Book.\n";
cout <<"\n\n\t\t\tPress R To Read Book.\n";
cout <<"\n\n\t\t\tPress D To Delete Book.\n";
cout <<"\n\n\t\t\tPress E To Exit The Program.\n\n";
cout <<"\tEnter Your choice\t=\t";
cin >>choice;

if (choice == 'b' || choice == 'B')
{
createbook ();
goto M;
}
else if (choice == 'f' || choice == 'F')
{
findbook ();
goto M;
}
else if (choice == 'i' || choice == 'I')
{
issuebook ();
goto M;
}
else if (choice == 'd' || choice == 'D')
{
deletebook ();
goto M;
}
else if (choice == 'r' || choice == 'R')
{
readbook ();
goto M;
}
else if (choice == 'e' || choice == 'E')
{
system ("pause");
}

}

void createbook ()
{
cout <<"\n\n\n\t\t\tCreating A Book\n\n";
ofstream outfile ("Intro.txt",ios::out | ios::app);
q=head;
p=new book;
p->next=NULL;
p->pre=NULL;
cout <<endl<<"\tEnter The Book Name\t=\t";
cin >>p->bname;
outfile <<p->bname<<endl;
cout <<endl<<"\tEnter The Book's Id\t=\t";
cin >>p->bid;
outfile <<p->bid<<endl;
cout <<"\tEnter The Book's Edition\t=\t";
cin >>p->bedition;
outfile <<p->bedition<<endl;
cout <<"\tEnter The Price of the Book\t=\t";
cin >>p->bprice;
outfile <<p->bprice<<endl;
if(head==NULL)
{
head=p;
}
else
{
while(q!=NULL)
{
q = q->next;
}
q->next=p;
p->pre=q;
}
outfile.close ();
}

void findbook ()
{
int i = p->bid;
cout<<"\tEnter The Book's Id\t=\t";
cin>>p->bid;
fstream infile;
infile.open ("Intro.txt");
if (i == p -> bid)
{
infile.open ("Intro.txt" , ios::app);
infile >>p->bid>>p->bprice;
infile >>p->bname;
infile >>p->bedition;
infile >>p->bprice;
cout<<"\tBook ID Is : "<<p->bid<<endl;
cout<<"\tThe Book Name Is : "<<p->bname<<endl;
cout<<"\tThe Book Edition Is : "<<p->bedition<<endl;
cout<<"\tThe Book's Price Is : "<<p->bprice<<endl;
infile.close();
}
else
cout <<"\tSorry Book ID Not Found\t=\t" ;
}

void deletebook ()
{
cout <<"\n\n\n\t\t\tDeleting A Book\n\n";
cout <<"\tEnter The Book Name You Want To Delete\t=\t";
cin >>name;
ofstream outfile;
for ( int x = 0 ; x < 100 ; x++ )
{
outfile << " " <<endl;
}
outfile.open(name/*, ios::trunc*/);
cout <<"\tThe Book Has Been Deleted\t=\t"<<p->bname;
}
void issuebook ()
{
cout <<"\n\n\t\t\tIssueing A Book\n\n";
cout <<"\tEnter The Name Of The Book To Issue\t=\t";
cin >>name;
ofstream outfile;
outfile.open (name,ios::trunc);
cout <<"\tPlease Enter Your Name\t=\t";
cin >>x->name;
outfile <<x->name<<endl;
cout <<"\tEnter Your C.N.I.C Number\t=\t";
cin >>x->cnic;
outfile <<x->cnic<<endl;
cout <<"\tThe Book You Have Borrowed Is\t=\t"<<p->bname;
outfile <<x->selectedbook;
outfile.close();
}

void readbook ()
{
ifstream infile;
cout <<endl<<"\tShow The Whole Book Record\t=\t";
cout <<endl<<"\tEnter The Book's Name\t=\t";
cin >>p->bname;
infile.open(p->bname);
while (!infile.eof())
{
infile >>p->bname;
infile >>p->bid;
infile >>p->bedition;
infile >>p->bprice;
cout <<endl<<p->bname<<endl;
cout <<endl<<"\tBook ID : "<<p->bid<<endl;
cout <<endl<<p->bedition<<endl;
cout <<endl<<p->bprice<<endl;
}
infile.close ();;
}
Topic archived. No new replies allowed.