Hello everyone
im currently making a library, and im new to using arrays, i have added some books to my library file using an array. i was wondering how would i go back and select the element in the file to delete. the area that im trying to code for delete is in red. can anyone please help
bool addbook(char books[MAX_BOOKS][5][SIZE], int cnt)
{
cin.ignore(80,'\n');
system("CLS");
cout<<"***************************\n";
cout<<" Add Book \n";
cout<<"***************************\n";
cout<<"Title: ";
cin.getline(books[cnt][0],SIZE);
cout<<"\n\nAuthor: ";
cin.getline(books[cnt][1],SIZE);
cout<<"\n\nPublisher: ";
cin.getline(books[cnt][2],SIZE);
cout<<"\n\nISBN: ";
cin.getline(books[cnt][3],SIZE);
cout<<"\n\nStatus 1=IN,2=OUT: ";
cin.getline(books[cnt][4],SIZE);
system("CLS");
cout<<"Book added.\n\n";
}
bool deletebook (char books[MAX_BOOKS][5][SIZE], int cnt)
{
char title[SIZE];
char author[SIZE];
char publisher[SIZE];
char isbn[SIZE];
system("CLS");
cout<<"***************************\n";
cout<<" Delete Book \n";
cout<<"***************************\n;
char deleteChoice;
cout<<"\n\nThis will delete the book. Are you sure (Y/N)?";
cin>>deleteChoice;
system("CLS");
if(deleteChoice == 'Y' || deleteChoice == 'y'){
ofstream outfile;
outfile.open(bookFilename);
cout<<"Book Deleted.\n\n";
}else{
cout<<"Book Delete Cancelled.\n\n";
}
}
void manageBooks(){
int currentCount =0;
char books[MAX_BOOKS][5][SIZE];
int choice = -1;
do{
system("CLS");
choice= bookMenu();
if(choice ==1){
if(addbook(books, currentCount))
currentCount++;
system ("pause");
cout<<"Current Count: "<<currentCount<<endl;
}
else if (choice ==2)
editbook();
else if (choice ==3){
if(deletebook(books, currentCount))
currentCount++;
system ("pause");
}
else if (choice ==4)
listBooks(false,books,currentCount);
else if (choice ==5)
checkinCheckout();
else if (choice ==6)
{
cout<<"\n\nSearch called\n\n";
system("PAUSE");
}
else if (choice ==7)
{
cout<<"\n\nSort called\n\n";
system("PAUSE");
}
else if (choice ==8)
cout<<"just going to exit the book section.";
else
{
cout<<"Invalid Book option.\n\n";
system("PAUSE");
}
}while (choice != 8);
}