I am working with a book database, in my code below the "changeEntry()" function is not working, in that function I want to override the old entry in the database and checking the entry by "show all Book entry", any help would be appreciated.
void addBook::changeEntry()
{ cout<<"Which book do you want to chnage?"<<endl;
cin>>count;
entry_struct InputBook;
cout << "Entry number " << (count ) << " : " << endl; // When you display the books, you add 1 to the count, but you don;t account for that here.
cout << "Authors First Name: ";
cin >> InputBook.newName; // Don't assign to newName. You should be changing firstName. newName is not needed.
entries[count] = InputBook;
string sInput;
cout << "Subject: ";
cin >> sInput;
if (sInput == "Chemistry")
{ // entries.push_back(InputBook); // This adds a new book. You don't want to do that.
entries[count].Topic = Chemistry; // This will get overlaid by the next statement
// entries[count] = InputBook; // You've already done this at line 82
}
}
Suggestion: You should make all changes to InputBook before assigning it to entries[count] at line 82.
BTW, this has nothing to do with overriding a member function.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Line 13: You're displaying it as user count +1. If the user entered 1 for the first book, you would be displaying 2.
Line 16,23,30: You're replacing entries[1]. What you want is entries[0] for the first book.
Suggest: At line 11, do the following:
count--;
This will adjust the count once from 1 based to 0 based. Adding 1 in line 13 would then be correct and the zero based reference to the vector will be correct in the remaining statements.